Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check checks that all of `obj`'s struct fields are provided by the JSON object encoded in `b`.
If there are any fields indicated by a `json` tag that are not present in the object encoded in `b`, an error will be returned indicating the missing fields.
If obj is not a struct, an error will be returned.
If a struct field has an empty `json` tag, or an omitempty tag, the absence of a corresponding key in b will not be considered an error.
The omit variadic argument can be used to omit fields from checking, so that only certain fields in a struct are checked.
Example:
type Foo struct {
A int `json:"a"`
B string `json:"b"`
}
func (f *Foo) UnmarshalJSON(b []byte) error {
type __ Foo
var g __
if err := Check(b, f); err != nil {
return err
}
if err := json.Unmarshal(b, &g); err != nil {
return err
}
*f = Foo(g)
return nil
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.