Encoding structs
Go struct types are usually encoded as JSON objects. This section shows the standard library tools that deal with the encoding of data types.
How to do it...
- Use
jsontags to annotate struct fields with their JSON keys:
type Config struct {
Version string `json:"ver"` // Encoded as "ver"
Name string // Encoded as "Name"
Type string `json:"type,omitempty"` // Encoded as "type",
// and will be omitted if
...