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

variant

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferType added in v0.2.0

func InferType[T ~string](candidates ...Candidate[T]) (enum.Entry[T], error)

InferType returns the type of the one candidate that is set.

Types

type Candidate added in v0.2.0

type Candidate[T ~string] struct {
	Type  enum.Entry[T]
	IsSet bool
}

func NewCandidate added in v0.2.0

func NewCandidate[T ~string](typ enum.Entry[T], isSet bool) Candidate[T]

type Variant

type Variant[X, Y any] struct {
	X X
	Y Y
}

A Variant decodes one JSON value into X or into Y. When both decode, X wins, so Y can be a type that takes any value: a secret comes back as a hash object in X, and a plain value in Y.

func (Variant[X, Y]) HasX

func (v Variant[X, Y]) HasX() bool

func (Variant[X, Y]) HasY

func (v Variant[X, Y]) HasY() bool

func (Variant[X, Y]) MarshalJSON

func (v Variant[X, Y]) MarshalJSON() ([]byte, error)

func (*Variant[X, Y]) UnmarshalJSON

func (v *Variant[X, Y]) UnmarshalJSON(bytes []byte) error

func (Variant[X, Y]) WithX

func (v Variant[X, Y]) WithX(action func(x *X))

func (Variant[X, Y]) WithY

func (v Variant[X, Y]) WithY(action func(y *Y))

Jump to

Keyboard shortcuts

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