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

variant

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Variant

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

A Variant represents a single JSON map entry having two different Go type representations X and Y. After JSON unmarshalling you can check with HasX, HasY which field has been detected, while X is preferred. An example usage is a Client DTO response which can either be struct representing a secret hash, or a simple string response if that's a non-sensitive value.

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