Documentation
¶
Index ¶
Constants ¶
View Source
const Null string = "null"
View Source
const Omitted string = ""
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
A Field provides metadata to indicate the presence of a value.
Use Field.Valid to check if an optional value was null or omitted.
A Field will always occur in the following structure, where it mirrors the original field in it's parent struct:
type ExampleObject struct {
Foo bool `json:"foo"`
Bar int `json:"bar"`
// ...
// JSON provides metadata about the object.
JSON struct {
Foo Field
Bar Field
// ...
} `json:"-"`
}
To differentiate a "nullish" value from the zero value, use the Field.Valid method.
if !example.JSON.Foo.Valid() {
println("Foo is null or omitted")
}
if example.Foo {
println("Foo is true")
} else {
println("Foo is false")
}
To differentiate if a field was omitted or the JSON value "null", use the Field.Raw method.
if example.JSON.Foo.Raw() == "null" {
println("Foo is null")
}
if example.JSON.Foo.Raw() == "" {
println("Foo was omitted")
}
Otherwise, if the field was invalid and couldn't be marshalled successfully, Field.Valid will be false and Field.Raw will not be empty.
func NewInvalidField ¶
Click to show internal directories.
Click to hide internal directories.