package prefs
import "tailscale.com/types/prefs"
Package prefs contains types and functions to work with arbitrary preference hierarchies.
Specifically, the package provides Item, List, Map, StructList and StructMap types which represent individual preferences in a user-defined prefs struct. A valid prefs struct must contain one or more exported fields of the preference types, either directly or within nested structs, but not pointers to these types. Additionally to preferences, a prefs struct may contain any number of non-preference fields that will be marshalled and unmarshalled but are otherwise ignored by the prefs package.
The preference types are compatible with the tailscale.com/cmd/viewer and tailscale.com/cmd/cloner utilities. It is recommended to generate a read-only view of the user-defined prefs structure and use it in place of prefs whenever the prefs should not be modified.
Index ¶
- Variables
- type BasicType
- type ImmutableType
- type Item
- func ItemOf[T any](v T, opts ...Options) Item[T]
- func ItemWithOpts[T any](opts ...Options) Item[T]
- func (p *Item) ClearManaged()
- func (p *Item) ClearValue() error
- func (i Item[T]) Clone() *Item[T]
- func (p Item) DefaultValue() T
- func (i Item[T]) Equal(i2 Item[T]) bool
- func (p Item) IsManaged() bool
- func (p Item) IsReadOnly() bool
- func (p Item) IsSet() bool
- func (p Item) MarshalJSON() ([]byte, error)
- func (p Item) MarshalJSONTo(out *jsontext.Encoder) error
- func (p *Item) SetDefaultValue(def T)
- func (i *Item[T]) SetManagedValue(val T)
- func (p *Item) SetReadOnly(readonly bool)
- func (i *Item[T]) SetValue(val T) error
- func (p *Item) UnmarshalJSON(b []byte) error
- func (p *Item) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (p Item) Value() T
- func (p Item) ValueOk() (val T, ok bool)
- type ItemView
- func ItemViewOf[T views.ViewCloner[T, V], V views.StructView[T]](i *Item[T]) ItemView[T, V]
- func (iv ItemView[T, V]) AsStruct() *Item[T]
- func (iv ItemView[T, V]) DefaultValue() V
- func (iv ItemView[T, V]) Equal(iv2 ItemView[T, V]) bool
- func (iv ItemView[T, V]) IsManaged() bool
- func (iv ItemView[T, V]) IsReadOnly() bool
- func (iv ItemView[T, V]) IsSet() bool
- func (iv ItemView[T, V]) MarshalJSON() ([]byte, error)
- func (iv ItemView[T, V]) MarshalJSONTo(out *jsontext.Encoder) error
- func (iv *ItemView[T, V]) UnmarshalJSON(b []byte) error
- func (iv *ItemView[T, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (iv ItemView[T, V]) Valid() bool
- func (iv ItemView[T, V]) Value() V
- func (iv ItemView[T, V]) ValueOk() (val V, ok bool)
- type List
- func ListOf[T ImmutableType](v []T, opts ...Options) List[T]
- func ListWithOpts[T ImmutableType](opts ...Options) List[T]
- func (p *List) ClearManaged()
- func (p *List) ClearValue() error
- func (l List[T]) Clone() *List[T]
- func (p List) DefaultValue() T
- func (l List[T]) Equal(l2 List[T]) bool
- func (p List) IsManaged() bool
- func (p List) IsReadOnly() bool
- func (p List) IsSet() bool
- func (p List) MarshalJSON() ([]byte, error)
- func (p List) MarshalJSONTo(out *jsontext.Encoder) error
- func (p *List) SetDefaultValue(def T)
- func (l *List[T]) SetManagedValue(val []T)
- func (p *List) SetReadOnly(readonly bool)
- func (l *List[T]) SetValue(val []T) error
- func (p *List) UnmarshalJSON(b []byte) error
- func (p *List) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (p List) Value() T
- func (p List) ValueOk() (val T, ok bool)
- func (l *List[T]) View() ListView[T]
- type ListView
- func (lv ListView[T]) AsStruct() *List[T]
- func (lv ListView[T]) DefaultValue() views.Slice[T]
- func (lv ListView[T]) Equal(lv2 ListView[T]) bool
- func (lv ListView[T]) IsManaged() bool
- func (lv ListView[T]) IsReadOnly() bool
- func (lv ListView[T]) IsSet() bool
- func (lv ListView[T]) MarshalJSON() ([]byte, error)
- func (lv ListView[T]) MarshalJSONTo(out *jsontext.Encoder) error
- func (lv *ListView[T]) UnmarshalJSON(b []byte) error
- func (lv *ListView[T]) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (lv ListView[T]) Valid() bool
- func (lv ListView[T]) Value() views.Slice[T]
- func (lv ListView[T]) ValueOk() (val views.Slice[T], ok bool)
- type Map
- func MapOf[K MapKeyType, V ImmutableType](v map[K]V, opts ...Options) Map[K, V]
- func MapWithOpts[K MapKeyType, V ImmutableType](opts ...Options) Map[K, V]
- func (p *Map) ClearManaged()
- func (p *Map) ClearValue() error
- func (m Map[K, V]) Clone() *Map[K, V]
- func (p Map) DefaultValue() T
- func (m Map[K, V]) Equal(m2 Map[K, V]) bool
- func (p Map) IsManaged() bool
- func (p Map) IsReadOnly() bool
- func (p Map) IsSet() bool
- func (p Map) MarshalJSON() ([]byte, error)
- func (p Map) MarshalJSONTo(out *jsontext.Encoder) error
- func (p *Map) SetDefaultValue(def T)
- func (p *Map) SetManagedValue(val T)
- func (p *Map) SetReadOnly(readonly bool)
- func (p *Map) SetValue(val T) error
- func (p *Map) UnmarshalJSON(b []byte) error
- func (p *Map) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (p Map) Value() T
- func (p Map) ValueOk() (val T, ok bool)
- func (m *Map[K, V]) View() MapView[K, V]
- type MapKeyType
- type MapView
- func (mv MapView[K, V]) AsStruct() *Map[K, V]
- func (mv MapView[K, V]) DefaultValue() views.Map[K, V]
- func (mv MapView[K, V]) Equal(mv2 MapView[K, V]) bool
- func (mv MapView[K, V]) IsSet() bool
- func (mv MapView[K, V]) Managed() bool
- func (mv MapView[K, V]) MarshalJSON() ([]byte, error)
- func (mv MapView[K, V]) MarshalJSONTo(out *jsontext.Encoder) error
- func (mv MapView[K, V]) ReadOnly() bool
- func (mv *MapView[K, V]) UnmarshalJSON(b []byte) error
- func (mv *MapView[K, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (mv MapView[K, V]) Valid() bool
- func (mv MapView[K, V]) Value() views.Map[K, V]
- func (mv MapView[K, V]) ValueOk() (val views.Map[K, V], ok bool)
- type Options
- type StructList
- func StructListOf[T views.Cloner[T]](v []T, opts ...Options) StructList[T]
- func StructListWithOpts[T views.Cloner[T]](opts ...Options) StructList[T]
- func (p *StructList) ClearManaged()
- func (p *StructList) ClearValue() error
- func (l StructList[T]) Clone() *StructList[T]
- func (p StructList) DefaultValue() T
- func (l StructList[T]) Equal(l2 StructList[T]) bool
- func (p StructList) IsManaged() bool
- func (p StructList) IsReadOnly() bool
- func (p StructList) IsSet() bool
- func (p StructList) MarshalJSON() ([]byte, error)
- func (p StructList) MarshalJSONTo(out *jsontext.Encoder) error
- func (p *StructList) SetDefaultValue(def T)
- func (l *StructList[T]) SetManagedValue(val []T)
- func (p *StructList) SetReadOnly(readonly bool)
- func (l *StructList[T]) SetValue(val []T) error
- func (p *StructList) UnmarshalJSON(b []byte) error
- func (p *StructList) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (p StructList) Value() T
- func (p StructList) ValueOk() (val T, ok bool)
- type StructListView
- func StructListViewOf[T views.ViewCloner[T, V], V views.StructView[T]](l *StructList[T]) StructListView[T, V]
- func (lv StructListView[T, V]) AsStruct() *StructList[T]
- func (lv StructListView[T, V]) DefaultValue() views.SliceView[T, V]
- func (lv StructListView[T, V]) Equal(lv2 StructListView[T, V]) bool
- func (lv StructListView[T, V]) IsManaged() bool
- func (lv StructListView[T, V]) IsReadOnly() bool
- func (lv StructListView[T, V]) IsSet() bool
- func (lv StructListView[T, V]) MarshalJSON() ([]byte, error)
- func (lv StructListView[T, V]) MarshalJSONTo(out *jsontext.Encoder) error
- func (lv *StructListView[T, V]) UnmarshalJSON(b []byte) error
- func (lv *StructListView[T, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (lv StructListView[T, V]) Valid() bool
- func (lv StructListView[T, V]) Value() views.SliceView[T, V]
- func (lv StructListView[T, V]) ValueOk() (val views.SliceView[T, V], ok bool)
- type StructMap
- func StructMapOf[K MapKeyType, V views.Cloner[V]](v map[K]V, opts ...Options) StructMap[K, V]
- func StructMapWithOpts[K MapKeyType, V views.Cloner[V]](opts ...Options) StructMap[K, V]
- func (p *StructMap) ClearManaged()
- func (p *StructMap) ClearValue() error
- func (m StructMap[K, V]) Clone() *StructMap[K, V]
- func (p StructMap) DefaultValue() T
- func (m StructMap[K, V]) Equal(m2 StructMap[K, V]) bool
- func (p StructMap) IsManaged() bool
- func (p StructMap) IsReadOnly() bool
- func (p StructMap) IsSet() bool
- func (p StructMap) MarshalJSON() ([]byte, error)
- func (p StructMap) MarshalJSONTo(out *jsontext.Encoder) error
- func (p *StructMap) SetDefaultValue(def T)
- func (l *StructMap[K, V]) SetManagedValue(val map[K]V)
- func (p *StructMap) SetReadOnly(readonly bool)
- func (l *StructMap[K, V]) SetValue(val map[K]V) error
- func (p *StructMap) UnmarshalJSON(b []byte) error
- func (p *StructMap) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (p StructMap) Value() T
- func (p StructMap) ValueOk() (val T, ok bool)
- type StructMapView
- func StructMapViewOf[K MapKeyType, T views.ViewCloner[T, V], V views.StructView[T]](m *StructMap[K, T]) StructMapView[K, T, V]
- func (mv StructMapView[K, T, V]) AsStruct() *StructMap[K, T]
- func (mv StructMapView[K, T, V]) DefaultValue() views.MapFn[K, T, V]
- func (mv StructMapView[K, T, V]) Equal(mv2 StructMapView[K, T, V]) bool
- func (mv StructMapView[K, T, V]) IsManaged() bool
- func (mv StructMapView[K, T, V]) IsReadOnly() bool
- func (mv StructMapView[K, T, V]) IsSet() bool
- func (mv StructMapView[K, T, V]) MarshalJSON() ([]byte, error)
- func (mv StructMapView[K, T, V]) MarshalJSONTo(out *jsontext.Encoder) error
- func (mv *StructMapView[K, T, V]) UnmarshalJSON(b []byte) error
- func (mv *StructMapView[K, T, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error
- func (mv StructMapView[K, T, V]) Valid() bool
- func (mv StructMapView[K, T, V]) Value() views.MapFn[K, T, V]
- func (mv StructMapView[K, T, V]) ValueOk() (val views.MapFn[K, T, V], ok bool)
Variables ¶
var ( // ErrManaged is the error returned when attempting to modify a managed preference. ErrManaged = errors.New("cannot modify a managed preference") // ErrReadOnly is the error returned when attempting to modify a read-only preference. ErrReadOnly = errors.New("cannot modify a read-only preference") )
Types ¶
type BasicType ¶
type BasicType interface { ~bool | constraints.Integer | constraints.Float | constraints.Complex | ~string }
BasicType is a constraint that allows types whose underlying type is a predeclared boolean, numeric, or string type.
type ImmutableType ¶
ImmutableType is a constraint that allows [BasicType]s and certain well-known immutable types.
type Item ¶
type Item[T any] struct { // contains filtered or unexported fields }
Item is a single preference item that can be configured. T must either be an immutable type or implement the views.ViewCloner interface.
func ItemOf ¶
ItemOf returns an Item configured with the specified value and Options.
func ItemWithOpts ¶
ItemWithOpts returns an unconfigured Item with the specified Options.
func (*Item) ClearManaged ¶
func (p *Item) ClearManaged()
ClearManaged clears the managed flag of the preference without altering its value.
func (*Item) ClearValue ¶
func (p *Item) ClearValue() error
ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (Item[T]) Clone ¶
Clone returns a copy of i that aliases no memory with i. It is a runtime error to call Item.Clone if T contains pointers but does not implement views.Cloner.
func (Item) DefaultValue ¶
func (p Item) DefaultValue() T
DefaultValue returns the default value of p.
func (Item[T]) Equal ¶
Equal reports whether i and i2 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 reports false.
func (Item) IsManaged ¶
func (p Item) IsManaged() bool
IsManaged reports whether p is managed via MDM, Group Policy, or similar means.
func (Item) IsReadOnly ¶
func (p Item) IsReadOnly() bool
IsReadOnly reports whether p is read-only and cannot be changed by user.
func (Item) IsSet ¶
func (p Item) IsSet() bool
IsSet reports whether p has a value set.
func (Item) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (Item) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*Item) SetDefaultValue ¶
func (p *Item) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*Item[T]) SetManagedValue ¶
func (i *Item[T]) SetManagedValue(val T)
SetManagedValue configures the preference with the specified value and marks the preference as managed.
func (*Item) SetReadOnly ¶
func (p *Item) SetReadOnly(readonly bool)
SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.
func (*Item[T]) SetValue ¶
SetValue configures the preference with the specified value. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (*Item) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*Item) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (Item) Value ¶
func (p Item) Value() T
Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.
func (Item) ValueOk ¶
func (p Item) ValueOk() (val T, ok bool)
ValueOk returns the value of p and true if the preference has a value set. Otherwise, it returns its default value and false.
type ItemView ¶
type ItemView[T views.ViewCloner[T, V], V views.StructView[T]] struct { // contains filtered or unexported fields }
ItemView is a read-only view of an Item[T], where T is a mutable type implementing views.ViewCloner.
func ItemViewOf ¶
func ItemViewOf[T views.ViewCloner[T, V], V views.StructView[T]](i *Item[T]) ItemView[T, V]
ItemViewOf returns a read-only view of i. It is used by tailscale.com/cmd/viewer.
func (ItemView[T, V]) AsStruct ¶
AsStruct implements views.StructView by returning a clone of the preference which aliases no memory with the original.
func (ItemView[T, V]) DefaultValue ¶
func (iv ItemView[T, V]) DefaultValue() V
DefaultValue returns a read-only view of the default value of the preference.
func (ItemView[T, V]) Equal ¶
Equal reports whether iv and iv2 are equal.
func (ItemView[T, V]) IsManaged ¶
IsManaged reports whether the preference is managed via MDM, Group Policy, or similar means.
func (ItemView[T, V]) IsReadOnly ¶
IsReadOnly reports whether the preference is read-only and cannot be changed by user.
func (ItemView[T, V]) IsSet ¶
IsSet reports whether the preference has a value set.
func (ItemView[T, V]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (ItemView[T, V]) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*ItemView[T, V]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*ItemView[T, V]) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (ItemView[T, V]) Valid ¶
Valid reports whether the underlying Item is non-nil.
func (ItemView[T, V]) Value ¶
func (iv ItemView[T, V]) Value() V
Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.
func (ItemView[T, V]) ValueOk ¶
ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.
type List ¶
type List[T ImmutableType] struct { // contains filtered or unexported fields }
List is a preference type that holds zero or more values of an ImmutableType T.
func ListOf ¶
func ListOf[T ImmutableType](v []T, opts ...Options) List[T]
ListOf returns a List configured with the specified value and Options.
func ListWithOpts ¶
func ListWithOpts[T ImmutableType](opts ...Options) List[T]
ListWithOpts returns an unconfigured List with the specified Options.
func (*List) ClearManaged ¶
func (p *List) ClearManaged()
ClearManaged clears the managed flag of the preference without altering its value.
func (*List) ClearValue ¶
func (p *List) ClearValue() error
ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (List[T]) Clone ¶
Clone returns a copy of l that aliases no memory with l.
func (List) DefaultValue ¶
func (p List) DefaultValue() T
DefaultValue returns the default value of p.
func (List[T]) Equal ¶
Equal reports whether l and l2 are equal.
func (List) IsManaged ¶
func (p List) IsManaged() bool
IsManaged reports whether p is managed via MDM, Group Policy, or similar means.
func (List) IsReadOnly ¶
func (p List) IsReadOnly() bool
IsReadOnly reports whether p is read-only and cannot be changed by user.
func (List) IsSet ¶
func (p List) IsSet() bool
IsSet reports whether p has a value set.
func (List) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (List) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*List) SetDefaultValue ¶
func (p *List) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*List[T]) SetManagedValue ¶
func (l *List[T]) SetManagedValue(val []T)
SetManagedValue configures the preference with the specified value and marks the preference as managed.
func (*List) SetReadOnly ¶
func (p *List) SetReadOnly(readonly bool)
SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.
func (*List[T]) SetValue ¶
SetValue configures the preference with the specified value. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (*List) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*List) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (List) Value ¶
func (p List) Value() T
Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.
func (List) ValueOk ¶
func (p List) ValueOk() (val T, ok bool)
ValueOk returns the value of p and true if the preference has a value set. Otherwise, it returns its default value and false.
func (*List[T]) View ¶
View returns a read-only view of l.
type ListView ¶
type ListView[T ImmutableType] struct { // contains filtered or unexported fields }
ListView is a read-only view of a List.
func (ListView[T]) AsStruct ¶
AsStruct implements views.StructView by returning a clone of the List which aliases no memory with the original.
func (ListView[T]) DefaultValue ¶
DefaultValue returns a read-only view of the default value of the preference.
func (ListView[T]) Equal ¶
Equal reports whether lv and lv2 are equal.
func (ListView[T]) IsManaged ¶
IsManaged reports whether the preference is managed via MDM, Group Policy, or similar means.
func (ListView[T]) IsReadOnly ¶
IsReadOnly reports whether the preference is read-only and cannot be changed by user.
func (ListView[T]) IsSet ¶
IsSet reports whether the preference has a value set.
func (ListView[T]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (ListView[T]) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*ListView[T]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*ListView[T]) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (ListView[T]) Valid ¶
Valid reports whether the underlying List is non-nil.
func (ListView[T]) Value ¶
Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.
func (ListView[T]) ValueOk ¶
ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.
type Map ¶
type Map[K MapKeyType, V ImmutableType] struct { // contains filtered or unexported fields }
Map is a preference type that holds immutable key-value pairs.
func MapOf ¶
func MapOf[K MapKeyType, V ImmutableType](v map[K]V, opts ...Options) Map[K, V]
MapOf returns a map configured with the specified value and Options.
func MapWithOpts ¶
func MapWithOpts[K MapKeyType, V ImmutableType](opts ...Options) Map[K, V]
MapWithOpts returns an unconfigured Map with the specified Options.
func (*Map) ClearManaged ¶
func (p *Map) ClearManaged()
ClearManaged clears the managed flag of the preference without altering its value.
func (*Map) ClearValue ¶
func (p *Map) ClearValue() error
ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (Map[K, V]) Clone ¶
Clone returns a copy of m that aliases no memory with m.
func (Map) DefaultValue ¶
func (p Map) DefaultValue() T
DefaultValue returns the default value of p.
func (Map[K, V]) Equal ¶
Equal reports whether m and m2 are equal.
func (Map) IsManaged ¶
func (p Map) IsManaged() bool
IsManaged reports whether p is managed via MDM, Group Policy, or similar means.
func (Map) IsReadOnly ¶
func (p Map) IsReadOnly() bool
IsReadOnly reports whether p is read-only and cannot be changed by user.
func (Map) IsSet ¶
func (p Map) IsSet() bool
IsSet reports whether p has a value set.
func (Map) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (Map) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*Map) SetDefaultValue ¶
func (p *Map) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*Map) SetManagedValue ¶
func (p *Map) SetManagedValue(val T)
SetManagedValue configures the preference with the specified value and marks the preference as managed.
func (*Map) SetReadOnly ¶
func (p *Map) SetReadOnly(readonly bool)
SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.
func (*Map) SetValue ¶
func (p *Map) SetValue(val T) error
SetValue configures the preference with the specified value. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (*Map) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*Map) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (Map) Value ¶
func (p Map) Value() T
Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.
func (Map) ValueOk ¶
func (p Map) ValueOk() (val T, ok bool)
ValueOk returns the value of p and true if the preference has a value set. Otherwise, it returns its default value and false.
func (*Map[K, V]) View ¶
View returns a read-only view of m.
type MapKeyType ¶
type MapKeyType interface { ~string | constraints.Integer | netip.Addr | netip.Prefix | netip.AddrPort }
MapKeyType is a constraint allowing types that can be used as Map and StructMap keys. To satisfy this requirement, a type must be comparable and must encode as a JSON string. See jsonv2.Marshal for more details.
type MapView ¶
type MapView[K MapKeyType, V ImmutableType] struct { // contains filtered or unexported fields }
MapView is a read-only view of a Map.
func (MapView[K, V]) AsStruct ¶
AsStruct implements views.StructView by returning a clone of the Map which aliases no memory with the original.
func (MapView[K, V]) DefaultValue ¶
DefaultValue returns a read-only view of the default value of the preference.
func (MapView[K, V]) Equal ¶
Equal reports whether mv and mv2 are equal.
func (MapView[K, V]) IsSet ¶
IsSet reports whether the preference has a value set.
func (MapView[K, V]) Managed ¶
Managed reports whether the preference is managed via MDM, Group Policy, or similar means.
func (MapView[K, V]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (MapView[K, V]) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (MapView[K, V]) ReadOnly ¶
ReadOnly reports whether the preference is read-only and cannot be changed by user.
func (*MapView[K, V]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*MapView[K, V]) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (MapView[K, V]) Valid ¶
Valid reports whether the underlying Map is non-nil.
func (MapView[K, V]) Value ¶
Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.
func (MapView[K, V]) ValueOk ¶
ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.
type Options ¶
type Options func(s *metadata)
Options are used to configure additional parameters of a preference.
var ( // ReadOnly is an option that marks preference as read-only. ReadOnly Options = markReadOnly // Managed is an option that marks preference as managed. Managed Options = markManaged )
type StructList ¶
StructList is a preference type that holds zero or more potentially mutable struct values.
func StructListOf ¶
func StructListOf[T views.Cloner[T]](v []T, opts ...Options) StructList[T]
StructListOf returns a StructList configured with the specified value and Options.
func StructListWithOpts ¶
func StructListWithOpts[T views.Cloner[T]](opts ...Options) StructList[T]
StructListWithOpts returns an unconfigured StructList with the specified Options.
func (*StructList) ClearManaged ¶
func (p *StructList) ClearManaged()
ClearManaged clears the managed flag of the preference without altering its value.
func (*StructList) ClearValue ¶
func (p *StructList) ClearValue() error
ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (StructList[T]) Clone ¶
func (l StructList[T]) Clone() *StructList[T]
Clone returns a copy of l that aliases no memory with l.
func (StructList) DefaultValue ¶
func (p StructList) DefaultValue() T
DefaultValue returns the default value of p.
func (StructList[T]) Equal ¶
func (l StructList[T]) Equal(l2 StructList[T]) bool
Equal reports whether l and l2 are equal. If the template type T implements an Equal(T) bool method, it will be used instead of the == operator for value comparison. It panics if T is not comparable.
func (StructList) IsManaged ¶
func (p StructList) IsManaged() bool
IsManaged reports whether p is managed via MDM, Group Policy, or similar means.
func (StructList) IsReadOnly ¶
func (p StructList) IsReadOnly() bool
IsReadOnly reports whether p is read-only and cannot be changed by user.
func (StructList) IsSet ¶
func (p StructList) IsSet() bool
IsSet reports whether p has a value set.
func (StructList) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (StructList) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*StructList) SetDefaultValue ¶
func (p *StructList) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*StructList[T]) SetManagedValue ¶
func (l *StructList[T]) SetManagedValue(val []T)
SetManagedValue configures the preference with the specified value and marks the preference as managed.
func (*StructList) SetReadOnly ¶
func (p *StructList) SetReadOnly(readonly bool)
SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.
func (*StructList[T]) SetValue ¶
func (l *StructList[T]) SetValue(val []T) error
SetValue configures the preference with the specified value. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (*StructList) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*StructList) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (StructList) Value ¶
func (p StructList) Value() T
Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.
func (StructList) ValueOk ¶
func (p StructList) ValueOk() (val T, ok bool)
ValueOk returns the value of p and true if the preference has a value set. Otherwise, it returns its default value and false.
type StructListView ¶
type StructListView[T views.ViewCloner[T, V], V views.StructView[T]] struct { // contains filtered or unexported fields }
StructListView is a read-only view of a StructList.
func StructListViewOf ¶
func StructListViewOf[T views.ViewCloner[T, V], V views.StructView[T]](l *StructList[T]) StructListView[T, V]
StructListViewOf returns a read-only view of l. It is used by tailscale.com/cmd/viewer.
func (StructListView[T, V]) AsStruct ¶
func (lv StructListView[T, V]) AsStruct() *StructList[T]
AsStruct implements views.StructView by returning a clone of the preference which aliases no memory with the original.
func (StructListView[T, V]) DefaultValue ¶
func (lv StructListView[T, V]) DefaultValue() views.SliceView[T, V]
DefaultValue returns a read-only view of the default value of the preference.
func (StructListView[T, V]) Equal ¶
func (lv StructListView[T, V]) Equal(lv2 StructListView[T, V]) bool
Equal reports whether iv and iv2 are equal.
func (StructListView[T, V]) IsManaged ¶
func (lv StructListView[T, V]) IsManaged() bool
IsManaged reports whether the preference is managed via MDM, Group Policy, or similar means.
func (StructListView[T, V]) IsReadOnly ¶
func (lv StructListView[T, V]) IsReadOnly() bool
IsReadOnly reports whether the preference is read-only and cannot be changed by user.
func (StructListView[T, V]) IsSet ¶
func (lv StructListView[T, V]) IsSet() bool
IsSet reports whether the preference has a value set.
func (StructListView[T, V]) MarshalJSON ¶
func (lv StructListView[T, V]) MarshalJSON() ([]byte, error)
MarshalJSON implements [json.Marshaler].
func (StructListView[T, V]) MarshalJSONTo ¶
func (lv StructListView[T, V]) MarshalJSONTo(out *jsontext.Encoder) error
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*StructListView[T, V]) UnmarshalJSON ¶
func (lv *StructListView[T, V]) UnmarshalJSON(b []byte) error
UnmarshalJSON implements [json.Unmarshaler].
func (*StructListView[T, V]) UnmarshalJSONFrom ¶
func (lv *StructListView[T, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (StructListView[T, V]) Valid ¶
func (lv StructListView[T, V]) Valid() bool
Valid reports whether the underlying StructList is non-nil.
func (StructListView[T, V]) Value ¶
func (lv StructListView[T, V]) Value() views.SliceView[T, V]
Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.
func (StructListView[T, V]) ValueOk ¶
func (lv StructListView[T, V]) ValueOk() (val views.SliceView[T, V], ok bool)
ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.
type StructMap ¶
type StructMap[K MapKeyType, V views.Cloner[V]] struct { // contains filtered or unexported fields }
StructMap is a preference type that holds potentially mutable key-value pairs.
func StructMapOf ¶
func StructMapOf[K MapKeyType, V views.Cloner[V]](v map[K]V, opts ...Options) StructMap[K, V]
StructMapOf returns a StructMap configured with the specified value and Options.
func StructMapWithOpts ¶
func StructMapWithOpts[K MapKeyType, V views.Cloner[V]](opts ...Options) StructMap[K, V]
StructMapWithOpts returns an unconfigured StructMap with the specified Options.
func (*StructMap) ClearManaged ¶
func (p *StructMap) ClearManaged()
ClearManaged clears the managed flag of the preference without altering its value.
func (*StructMap) ClearValue ¶
func (p *StructMap) ClearValue() error
ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (StructMap[K, V]) Clone ¶
Clone returns a copy of m that aliases no memory with m.
func (StructMap) DefaultValue ¶
func (p StructMap) DefaultValue() T
DefaultValue returns the default value of p.
func (StructMap[K, V]) Equal ¶
Equal reports whether m and m2 are equal. If the template type V implements an Equal(V) bool method, it will be used instead of the == operator for value comparison. It panics if T is not comparable.
func (StructMap) IsManaged ¶
func (p StructMap) IsManaged() bool
IsManaged reports whether p is managed via MDM, Group Policy, or similar means.
func (StructMap) IsReadOnly ¶
func (p StructMap) IsReadOnly() bool
IsReadOnly reports whether p is read-only and cannot be changed by user.
func (StructMap) IsSet ¶
func (p StructMap) IsSet() bool
IsSet reports whether p has a value set.
func (StructMap) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (StructMap) MarshalJSONTo ¶
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*StructMap) SetDefaultValue ¶
func (p *StructMap) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*StructMap[K, V]) SetManagedValue ¶
func (l *StructMap[K, V]) SetManagedValue(val map[K]V)
SetManagedValue configures the preference with the specified value and marks the preference as managed.
func (*StructMap) SetReadOnly ¶
func (p *StructMap) SetReadOnly(readonly bool)
SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.
func (*StructMap[K, V]) SetValue ¶
SetValue configures the preference with the specified value. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.
func (*StructMap) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*StructMap) UnmarshalJSONFrom ¶
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (StructMap) Value ¶
func (p StructMap) Value() T
Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.
func (StructMap) ValueOk ¶
func (p StructMap) ValueOk() (val T, ok bool)
ValueOk returns the value of p and true if the preference has a value set. Otherwise, it returns its default value and false.
type StructMapView ¶
type StructMapView[K MapKeyType, T views.ViewCloner[T, V], V views.StructView[T]] struct { // contains filtered or unexported fields }
StructMapView is a read-only view of a StructMap.
func StructMapViewOf ¶
func StructMapViewOf[K MapKeyType, T views.ViewCloner[T, V], V views.StructView[T]](m *StructMap[K, T]) StructMapView[K, T, V]
StructMapViewOf returns a read-only view of m. It is used by tailscale.com/cmd/viewer.
func (StructMapView[K, T, V]) AsStruct ¶
func (mv StructMapView[K, T, V]) AsStruct() *StructMap[K, T]
AsStruct implements views.StructView by returning a clone of the preference which aliases no memory with the original.
func (StructMapView[K, T, V]) DefaultValue ¶
func (mv StructMapView[K, T, V]) DefaultValue() views.MapFn[K, T, V]
DefaultValue returns a read-only view of the default value of the preference.
func (StructMapView[K, T, V]) Equal ¶
func (mv StructMapView[K, T, V]) Equal(mv2 StructMapView[K, T, V]) bool
Equal reports whether mv and mv2 are equal.
func (StructMapView[K, T, V]) IsManaged ¶
func (mv StructMapView[K, T, V]) IsManaged() bool
Managed reports whether the preference is managed via MDM, Group Policy, or similar means.
func (StructMapView[K, T, V]) IsReadOnly ¶
func (mv StructMapView[K, T, V]) IsReadOnly() bool
ReadOnly reports whether the preference is read-only and cannot be changed by user.
func (StructMapView[K, T, V]) IsSet ¶
func (mv StructMapView[K, T, V]) IsSet() bool
IsSet reports whether the preference has a value set.
func (StructMapView[K, T, V]) MarshalJSON ¶
func (mv StructMapView[K, T, V]) MarshalJSON() ([]byte, error)
MarshalJSON implements [json.Marshaler].
func (StructMapView[K, T, V]) MarshalJSONTo ¶
func (mv StructMapView[K, T, V]) MarshalJSONTo(out *jsontext.Encoder) error
MarshalJSONTo implements jsonv2.MarshalerTo.
func (*StructMapView[K, T, V]) UnmarshalJSON ¶
func (mv *StructMapView[K, T, V]) UnmarshalJSON(b []byte) error
UnmarshalJSON implements [json.Unmarshaler].
func (*StructMapView[K, T, V]) UnmarshalJSONFrom ¶
func (mv *StructMapView[K, T, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error
UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.
func (StructMapView[K, T, V]) Valid ¶
func (mv StructMapView[K, T, V]) Valid() bool
Valid reports whether the underlying StructMap is non-nil.
func (StructMapView[K, T, V]) Value ¶
func (mv StructMapView[K, T, V]) Value() views.MapFn[K, T, V]
Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.
func (StructMapView[K, T, V]) ValueOk ¶
func (mv StructMapView[K, T, V]) ValueOk() (val views.MapFn[K, T, V], ok bool)
ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.
Source Files ¶
item.go list.go map.go options.go prefs.go struct_list.go struct_map.go
Directories ¶
Path | Synopsis |
---|---|
types/prefs/prefs_example | Package prefs_example contains a Prefs type, which is like tailscale.com/ipn.Prefs, but uses the prefs package to enhance individual preferences with state and metadata. |
- Version
- v1.84.0 (latest)
- Published
- May 21, 2025
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 2 days ago –
Tools for package owners.