package opt
import "tailscale.com/types/opt"
Package opt defines optional types.
Index ¶
- type Bool
- func NewBool(b bool) Bool
- func (b *Bool) Clear()
- func (b Bool) EqualBool(v bool) bool
- func (b Bool) Get() (v bool, ok bool)
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b *Bool) Scan(src any) error
- func (b *Bool) Set(v bool)
- func (b *Bool) UnmarshalJSON(j []byte) error
- type BoolFlag
- type Value
- func ValueOf[T any](v T) Value[T]
- 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
Types ¶
type Bool ¶
type Bool string
Bool represents an optional boolean to be JSON-encoded. The string is 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 the explicit unset value be exchanged over an encoding/json "omitempty" field without it being dropped.
func NewBool ¶
NewBool constructs a new Bool value equal to b. The returned Bool is set, unless Set("") or Clear() methods are called.
func (*Bool) Clear ¶
func (b *Bool) Clear()
func (Bool) EqualBool ¶
EqualBool reports whether b is equal to v. If b is empty or not a valid bool, it reports false.
func (Bool) Get ¶
func (Bool) MarshalJSON ¶
func (*Bool) Scan ¶
Scan implements database/sql.Scanner.
func (*Bool) Set ¶
func (*Bool) UnmarshalJSON ¶
type BoolFlag ¶
type BoolFlag struct { *Bool }
BoolFlag is a wrapper for Bool that implements flag.Value.
func (*BoolFlag) Set ¶
Set the value of b, using any value supported by strconv.ParseBool.
func (*BoolFlag) String ¶
String returns "true" or "false" if the value is set, or an empty string otherwise.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
Value is an optional value to be JSON-encoded. With encoding/json, a zero Value is marshaled as a JSON null. With github.com/go-json-experiment/json, a zero Value is omitted from the JSON object if the Go struct field specified with omitzero. The omitempty tag option should never be used with Value fields.
func ValueOf ¶
ValueOf returns an optional Value containing the specified value. It treats nil slices and maps as empty slices and maps.
func (*Value[T]) Clear ¶
func (o *Value[T]) Clear()
Clear resets o to an empty state.
func (Value[T]) Equal ¶
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 used instead of the == operator for value comparison. If T is not comparable, it returns false.
func (Value[T]) Get ¶
func (o Value[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 ¶
Get returns the value and a flag indicating whether the value is set.
func (Value[T]) GetOr ¶
func (o Value[T]) GetOr(def T) T
GetOr returns the value of o or def if a value hasn't been set.
func (*Value[T]) IsSet ¶
IsSet reports whether o has a value set.
func (Value[T]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (Value[T]) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*Value[T]) Set ¶
func (o *Value[T]) Set(v T)
Set assigns the specified value to the optional value o.
func (Value[T]) String ¶
String implements fmt.Stringer.
func (*Value[T]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*Value[T]) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
Source Files ¶
bool.go value.go
- Version
- v1.84.1 (latest)
- Published
- May 29, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 1 day ago –
Tools for package owners.