type Employee struct {
Name string
Number int
Boss *Employyee
Hired time.Time
}
%+v) to pretty print a struct and it’s fieldsmap[string]MyStruct) however it is really bad practice to do this because a map’s internal structure is dynamic
map[string]*MyStruct)++) on fields of structs by direct access (e.g. myMap["thing"].IntField++)
type blah struct{...}, that no longer is the case - structs with different names will always be different types even if they have the same field names and typestype thing1 struct {
field int
}
type thing2 struct {
field int
}
func main() {
a := thing1{field: 1}
b := thing2{field: 1}
a = thing1(b) // Valid
}
thing *myStruct, thing.field is equivalent to dereferencing (*thing).field
map[int]struct{}) or creating a chan struct{} to be a “complete” notifier without the need to pass any data if that isn’t neededtype Response struct {
Data string `json:"data"` // Only exported fields are included in a marshalled JSON string
Status int `json:"status"`
}
func main() {
// Serializing
r := Response{"Some data", 200}
j, _ := json.Marshal(r)
// j will be []byte containing "{"data":"Some data","status":200}"
// Deserializing
var r2 Response
_ = json.Unmarshal(j, &r2)
}