opt
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package opt defines optional types.
Index¶
- Constants
- type Bool
- type BoolFlag
- type Value
- func (o *Value[T]) Clear()
- func (o Value[T]) Equal(v Value[T]) bool
- func (o Value[T]) Get() T
- func (o Value[T]) GetOk() (v T, ok bool)
- func (o Value[T]) GetOr(def T) T
- func (o *Value[T]) IsSet() bool
- func (o Value[T]) MarshalJSON() ([]byte, error)
- func (o Value[T]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (o *Value[T]) Set(v T)
- func (o Value[T]) String() string
- func (o *Value[T]) UnmarshalJSON(b []byte) error
- func (o *Value[T]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
Constants¶
const (// True is the encoding of an explicit true.True =Bool("true")// False is the encoding of an explicit false.False =Bool("false")// ExplicitlyUnset is the encoding used by a null// JSON value. It is a synonym for the empty string.ExplicitlyUnset =Bool("unset")// Empty means the Bool is unset and it's neither// true nor false.Empty =Bool(""))
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeBool¶
type Boolstring
Bool represents an optional boolean to be JSON-encoded. The stringis either "true", "false", or the empty string to mean unset.
As a special case, the underlying string may also be the string"unset" as as a synonym for the empty string. This lets theexplicit unset value be exchanged over an encoding/json "omitempty"field without it being dropped.
funcNewBool¶added inv1.58.0
NewBool constructs a new Bool value equal to b. The returned Bool is set,unless Set("") or Clear() methods are called.
func (Bool)EqualBool¶added inv0.100.0
EqualBool reports whether b is equal to v.If b is empty or not a valid bool, it reports false.
func (Bool)MarshalJSON¶
func (Bool)Normalized¶added inv1.92.0
Normalized returns the normalized form of b, mapping "unset" to ""and leaving other values unchanged.
func (*Bool)UnmarshalJSON¶
typeBoolFlag¶added inv1.74.0
type BoolFlag struct {*Bool}BoolFlag is a wrapper for Bool that implementsflag.Value.
func (*BoolFlag)Set¶added inv1.74.0
Set the value of b, using any value supported bystrconv.ParseBool.
typeValue¶added inv1.70.0
type Value[Tany] struct {// contains filtered or unexported fields}
Value is an optional value to be JSON-encoded.Withencoding/json, a zero Value is marshaled as a JSON null.Withgithub.com/go-json-experiment/json, a zero Value is omitted from theJSON object if the Go struct field specified with omitzero.The omitempty tag option should never be used with Value fields.
funcValueOf¶added inv1.70.0
ValueOf returns an optional Value containing the specified value.It treats nil slices and maps as empty slices and maps.
func (Value[T])Equal¶added inv1.70.0
Equal reports whether o is equal to v.Two optional values are equal if both are empty,or if both are set and the underlying values are equal.If the template type T implements an Equal(T) bool method, it will be usedinstead of the == operator for value comparison.If T is not comparable, it returns false.
func (Value[T])Get¶added inv1.70.0
func (oValue[T]) Get() T
Get returns the value of o.If a value hasn't been set, a zero value of T will be returned.
func (Value[T])GetOk¶added inv1.70.0
Get returns the value and a flag indicating whether the value is set.
func (Value[T])GetOr¶added inv1.72.0
func (oValue[T]) GetOr(def T) T
GetOr returns the value of o or def if a value hasn't been set.
func (Value[T])MarshalJSON¶added inv1.70.0
MarshalJSON implements [json.Marshaler].
func (Value[T])MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*Value[T])Set¶added inv1.70.0
func (o *Value[T]) Set(v T)
Set assigns the specified value to the optional value o.
func (*Value[T])UnmarshalJSON¶added inv1.70.0
UnmarshalJSON implements [json.Unmarshaler].
func (*Value[T])UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.