Documentation
¶
Overview ¶
Package jsonx holds the encoding/json/v2 options every chok body uses.
json/v2 has no default representation for time.Duration; chok writes one as its String form ("1h30m0s"), the way configuration spells it, and reads either that string or an integer count of nanoseconds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Options = json.JoinOptions( json.WithMarshalers(json.MarshalToFunc(func(enc *jsontext.Encoder, d time.Duration) error { return enc.WriteToken(jsontext.String(d.String())) })), json.WithUnmarshalers(json.UnmarshalFromFunc(func(dec *jsontext.Decoder, d *time.Duration) error { tok, err := dec.ReadToken() if err != nil { return err } switch tok.Kind() { case '"': v, err := time.ParseDuration(tok.String()) if err != nil { return err } *d = v case '0': n, err := tok.Int() if err != nil { return err } *d = time.Duration(n) default: return errDuration } return nil })), )
Options apply to every request and response body.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.