Documentation ¶
Index ¶
Constants ¶
View Source
const ( ErrMalformedJSON = "given malformed JSON" ErrNotGivenStruct = "not given a struct in the raw stream" )
Variables ¶
View Source
var ( ErrGivenNonStringKey = errors.New("given object with non-string key") ErrMissingInlineField = errors.New("target struct missing specified inline field") ErrNotGivenMutable = errors.New("not given something which we can assign to") ErrNotStructHolder = errors.New("holder is not a struct") ErrInlineNotRightMap = errors.New("target's inline field is not a map[string]interface{}") ErrUnsettableInlineField = errors.New("target struct's inline field not assignable") )
Functions ¶
func Contains ¶
func Contains[S ~[]E, E comparable](s S, v E) bool
Contains reports whether v is present in s.
func Index ¶
func Index[S ~[]E, E comparable](s S, v E) int
Index returns the index of the first occurrence of v in s, or -1 if not present.
func InlineUnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON object into a struct, with support for inline fields. Inline fields are fields that are not explicitly defined in the struct, but are instead stored in a map[string]interface{} field with the tag `json:"-,inline"`.
Example:
type MyStruct struct { ExplicitField string `json:"explicit"` InlineField map[string]interface{} `json:"-,inline"` } func (target *MyStruct) UnmarshalJSON(raw []byte) (err error) { err = inline.UnmarshalJSON(target, raw) if err == nil { target.MetaData = nil } return } raw := []byte(`{"explicit":"value","extra":42}`) var target MyStruct err := json.UnmarshalJSON(&target, raw) if err != nil { panic(err) } fmt.Println(target.ExplicitField) // "value" fmt.Println(target.InlineField) // map[extra:42]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.