Documentation ¶
Overview ¶
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 (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) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) 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) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) error
- func (p Item) Value() T
- func (p Item) ValueOk() (val T, ok bool)
- type ItemView
- 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]) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) error
- func (iv *ItemView[T, V]) UnmarshalJSON(b []byte) error
- func (iv *ItemView[T, V]) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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 (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) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) 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) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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]) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) error
- func (lv *ListView[T]) UnmarshalJSON(b []byte) error
- func (lv *ListView[T]) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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 (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) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) 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) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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]) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) error
- func (mv MapView[K, V]) ReadOnly() bool
- func (mv *MapView[K, V]) UnmarshalJSON(b []byte) error
- func (mv *MapView[K, V]) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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 (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) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) 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) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) error
- func (p StructList) Value() T
- func (p StructList) ValueOk() (val T, ok bool)
- type StructListView
- 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]) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) error
- func (lv *StructListView[T, V]) UnmarshalJSON(b []byte) error
- func (lv *StructListView[T, V]) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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 (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) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) 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) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) error
- func (p StructMap) Value() T
- func (p StructMap) ValueOk() (val T, ok bool)
- type StructMapView
- 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]) MarshalJSONV2(out *jsontext.Encoder, opts jsonv2.Options) error
- func (mv *StructMapView[K, T, V]) UnmarshalJSON(b []byte) error
- func (mv *StructMapView[K, T, V]) UnmarshalJSONV2(in *jsontext.Decoder, opts jsonv2.Options) 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)
Constants ¶
This section is empty.
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 readonly preference. ErrReadOnly = errors.New("cannot modify a readonly preference") )
Functions ¶
This section is empty.
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 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) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (Item) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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]) 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]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (ItemView[T, V]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
func (*ItemView[T, V]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*ItemView[T, V]) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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) DefaultValue ¶
func (p List) DefaultValue() T
DefaultValue returns the default value of p.
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) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (List) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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.
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]) 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]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (ListView[T]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
func (*ListView[T]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].
func (*ListView[T]) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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) DefaultValue ¶
func (p Map) DefaultValue() T
DefaultValue returns the default value of p.
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) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (Map) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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.
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]) 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]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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]) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
type Options ¶
type Options func(s *metadata)
Options are used to configure additional parameters of a preference.
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) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (StructList) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
func (*StructListView[T, V]) UnmarshalJSON ¶
func (lv *StructListView[T, V]) UnmarshalJSON(b []byte) error
UnmarshalJSON implements [json.Unmarshaler].
func (*StructListView[T, V]) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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.
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) 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) MarshalJSON ¶
MarshalJSON implements [json.Marshaler].
func (StructMap) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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 readonly 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]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
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]) UnmarshalJSONV2 ¶
UnmarshalJSONV2 implements jsonv2.UnmarshalerV2.
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
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.
|
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. |