Documentation
¶
Overview ¶
Serialization utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlattenStructToJSON ¶
Flatten a struct to a JSON object.
We have many structs that look like ¶
type Foo struct {
Field1 A
Field2 B
SomeMap map[string]Foobar
}
That are meant to be converted to JSON as ¶
{
"field1": ...,
"field2": ...,
"key1": ..., // Key of SomeMap
"key2": ..., // Key of SomeMap
...
}
This function handles conversion to a JSON object that can then be serialized using the regular `json.Marshal`.
Conventions:
- all field names MUST have a tag `json`.
- a field holding a map MAY have a tag `flatten`, in which case the map is flattened into the containing struct, as above
- a field hodling a struct MAY have a tag `flatten`, in which case the struct is flattened into the containing struct
- a field MAY specify `omitempty` as the second value of `json` to specify that zero values should be skipped
This function should never panic.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.