jsonx

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL