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

optional

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignPtrString

func AssignPtrString[TO, FROM ~string](changed *bool, target *TO, src *FROM)

func AssignPtrValue

func AssignPtrValue[T comparable](changed *bool, target, src *T)

Types

type Option

type Option[T any] []T

Option is a generic type that can hold a value of type T or be empty (None).

It must use the slice type to work with "chi" form values binding: * non-existing value are represented as an empty slice (None) * existing value is represented as a slice with one element (Some) * multiple values are represented as a slice with multiple elements (Some), the Value is the first element (not well-defined in this case)

func FromMapLookup

func FromMapLookup[K comparable, V any](m map[K]V, k K) Option[V]

func FromNonDefault

func FromNonDefault[T comparable](v T) Option[T]

func FromPtr

func FromPtr[T any](v *T) Option[T]

func None

func None[T any]() Option[T]

func ParseBool

func ParseBool(s string) Option[bool]

ParseBool get the corresponding optional.Option[bool] of a string using strconv.ParseBool

func Some

func Some[T any](v T) Option[T]

func (Option[T]) Has

func (o Option[T]) Has() bool

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

func (Option[T]) MarshalYAML

func (o Option[T]) MarshalYAML() (any, error)

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(data []byte) error

func (*Option[T]) UnmarshalYAML

func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error

func (Option[T]) Value

func (o Option[T]) Value() T

func (Option[T]) ValueOrDefault

func (o Option[T]) ValueOrDefault(v T) T

Jump to

Keyboard shortcuts

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