This is the struct I have:
type Resource struct {
Name string `json:"name"`
Ranges struct {
Range []struct {
Begin int `json:"begin"`
End int `json:"end"`
} `json:"range"`
} `json:"ranges,omitempty"`
Role string `json:"role,omitempty"`
Type string `json:"type"`
Scalar Scalar `json:"scalar,omitempty"`
}
I don't know how to make fields in the JSON not null. For example, struct Range like that:
{
"name": "cpus",
"ranges": {
"range": null
},
"type": "SCALAR",
"scalar": {
"value": 1
}
}, {
"name": "mem",
"ranges": {
"range": null
}
Rangefield so that it isn'tnil, or add,omitemptyto the json tag so that the json property is omitted if theRangefield isnil. See here: play.golang.org/p/GWWm5yAP7lUjson.Marshalerinterface and have it decide how it's gonna be marshaled if it's empty or nil. play.golang.org/p/UJK5cjkctIw