Help us shape the future of Go! Take the 2026 Go Developer Survey

options

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package options is the state of the options of jsontext and of the v2 json package: both packages take the same Options, so that the options of one may be given to the functions of the other, as encoding/json/v2 and encoding/json/jsontext allow. An Options can't be made outside this module: its method takes a type of this internal package.

Index

Constants

DefaultV1Flags are the properties which DefaultOptionsV1 of the root package sets to true, and DefaultOptionsV2 of the v2 json package to false: the ones whose defaults differ between encoding/json and encoding/json/v2.

View Source
const V1OptionFlags = maxV1OptionFlag - ParseBytesWithLooseRFC4648

V1OptionFlags are the properties of the semantics of encoding/json: the flags from ParseBytesWithLooseRFC4648 to the last one, which the flag after it less the first one sets.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool uint8

Bool is the option of a property which is true or false: the index of the bit of its flag shifted by one bit, with the value as the lowest bit. It is a byte, which an Options holds without an allocation, as the runtime has the values of the bytes: an option made for each call, as encoding/json/v2's are, costs nothing more.

func (Bool) ApplyTo

func (o Bool) ApplyTo(c *Config)

ApplyTo sets the property of o in c.

type Config

type Config struct {
	Set   Flags // the properties which an option set
	Value Flags // the values of the properties which were set; the others are false
	// the properties which are not booleans, valid when their bits are in Set
	Indent       string
	Prefix       string
	Marshalers   any // the *Marshalers of the v2 json package
	Unmarshalers any // the *Unmarshalers of the v2 json package
}

Config is the state of the options: the properties which were set, and their values.

func (*Config) Apply

func (c *Config) Apply(opts []Options)

Apply sets the options in order: an option set later overrides a property set by an earlier one. A Bool, as most options are, is applied without a call of its method.

func (*Config) ApplyTo

func (c *Config) ApplyTo(dst *Config)

ApplyTo sets the properties of c in dst: a Config is itself an option of the properties it sets.

func (*Config) Has

func (c *Config) Has(f Flags) bool

Has reports whether the property f is true.

func (*Config) Same

func (c *Config) Same(d *Config) bool

Same reports whether c sets the same options as d. The properties which are not booleans are compared only if they are set; the marshalers and unmarshalers by identity.

type Flags

type Flags uint64

Flags are properties which are true or false, and, for the properties whose values are not booleans, the bits which show that they are set.

const (
	AllowDuplicateNames Flags = 1 << iota
	AllowInvalidUTF8
	EscapeForHTML
	EscapeForJS
	PreserveRawStrings
	CanonicalizeRawInts
	CanonicalizeRawFloats
	ReorderRawObjects
	SpaceAfterColon
	SpaceAfterComma
	Multiline
	IndentSet // WithIndent was given: Config.Indent
	PrefixSet // WithIndentPrefix was given: Config.Prefix
	// OmitTopLevelNewline is set by the functions and methods which format a single value, whose output has no
	// line feed after the value, as an Encoder writes.
	OmitTopLevelNewline
)

The properties of the encoders and the decoders of jsontext.

const (
	StringifyNumbers Flags = maxCoderFlag << iota
	Deterministic
	FormatNilMapAsNull
	FormatNilSliceAsNull
	MatchCaseInsensitiveNames
	OmitZeroStructFields
	RejectUnknownMembers
	MarshalersSet   // WithMarshalers was given: Config.Marshalers
	UnmarshalersSet // WithUnmarshalers was given: Config.Unmarshalers
	// StringTag is set by no option: the encoder which a method or a function of a value of a field of the `string`
	// option is given has it, by which MarshalEncode of the encoder encodes the value as such a value, as
	// encoding/json/v2 has it, until an object or an array begins.
	StringTag
	// UnmarshalAnyWithRawNumber is set by no option: the decoder which a Decoder of the root package gives
	// UnmarshalJSONFrom after UseNumber has it, by which UnmarshalDecode of the decoder decodes a number into an empty
	// interface as a json.Number, as encoding/json/v2 has it for encoding/json.
	UnmarshalAnyWithRawNumber
)

The properties of marshaling and unmarshaling Go values, of the v2 json package.

const (
	ParseBytesWithLooseRFC4648 Flags = maxArshalFlag << iota
	ParseTimeWithLooseRFC3339
	UnmarshalArrayFromAnyLength
	MergeWithLegacySemantics
	MatchCaseSensitiveDelimiter
	CallMethodsWithLegacySemantics
	FormatByteArrayAsArray
	FormatBytesWithLegacySemantics
	FormatDurationAsNano
	ReportErrorsWithLegacySemantics
	StringifyWithLegacySemantics
	OmitEmptyWithLegacySemantics
)

The properties of marshaling and unmarshaling Go values by the semantics of encoding/json ( v1 ), which the options of the root package set, as the ones of encoding/json do: the v2 json package applies each of them, alone or with the others.

type Indent

type Indent struct {
	S      string
	Prefix bool
}

Indent is the option of WithIndent or WithIndentPrefix of jsontext, which implies Multiline.

func (Indent) ApplyTo

func (o Indent) ApplyTo(c *Config)

ApplyTo sets the indentation or the prefix of o in c, and Multiline.

type Options

type Options interface {
	ApplyTo(c *Config)
}

Options is an option, or a set of them, which sets properties of a Config.

func BoolOf

func BoolOf(f Flags, v bool) Options

BoolOf returns the option which sets the property f, a single flag, to v.

Jump to

Keyboard shortcuts

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