Debugging Go (golang) code in Windows
Date : March 29 2020, 07:55 AM
|
Pointers and debugging in golang
Date : March 29 2020, 07:55 AM
hop of those help? You're not using pointers throughout. Start off with a Registry of type: type Registry []*Broker
|
Debugging a JSON error from Golang
Date : March 29 2020, 07:55 AM
I wish this helpful for you One way to both accept null values, and to not print anything if published_at is null, is to set PublishedAt field to a pointer value : type Movie struct {
Title string `json:"title"`
PublishedAt *time.Time `json:"published_at"`
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
// check the full type of an error raised when Unmarshaling a json string
func main() {
var test struct {
Clock time.Time
}
buf := bytes.NewBufferString(`{"Clock":null}`)
dec := json.NewDecoder(buf)
// ask to decode an invalid null value into a flat time.Time field :
err := dec.Decode(&test)
// print the details of the returned error :
fmt.Printf("%#v\n", err)
}
// Output :
&time.ParseError{Layout:"\"2006-01-02T15:04:05Z07:00\"", Value:"null", LayoutElem:"\"", ValueElem:"null", Message:""}
if terr, ok := err.(*time.ParseError); ok {
// in the example : Movie has one single time.Time field ;
// if a time.ParseError occured, it was while trying to read that field
fmt.Println("Error when trying to read 'published_at' value", terr)
// you can leave the field to its zero value,
// or if you switched to a pointer field :
m.PublishedAt = nil
}
if terr, ok := err.(*time.ParseError); ok {
if m.ProducedAt.IsZero() {
fmt.Println("Error when trying to read 'produced_at' value", terr)
}
if m.PublishedAt == zero {
fmt.Println("Error when trying to read 'published_at' value", terr)
}
}
|
Avoid debugging information on golang
Tag : go , By : Peter Leung
Date : March 29 2020, 07:55 AM
|
debugging golang in intellij - not finding relative files
Date : March 29 2020, 07:55 AM
|