prefs
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 prefs contains types and functions to work with arbitrarypreference hierarchies.
Specifically, the package providesItem,List,Map,StructList andStructMaptypes 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 ofnon-preference fields that will be marshalled and unmarshalled but areotherwise ignored by the prefs package.
The preference types are compatible with thetailscale.com/cmd/viewer andtailscale.com/cmd/cloner utilities. It is recommended to generate a read-only viewof the user-defined prefs structure and use it in place of prefs whenever the prefsshould 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) 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 (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 (p *List) ClearManaged()
- func (p *List) ClearValue() error
- func (ls List[T]) Clone() *List[T]
- func (p List) DefaultValue() T
- func (ls 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 (ls *List[T]) SetManagedValue(val []T)
- func (p *List) SetReadOnly(readonly bool)
- func (ls *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 (ls *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 (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 (p *StructList) ClearManaged()
- func (p *StructList) ClearValue() error
- func (ls StructList[T]) Clone() *StructList[T]
- func (p StructList) DefaultValue() T
- func (ls 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 (ls *StructList[T]) SetManagedValue(val []T)
- func (p *StructList) SetReadOnly(readonly bool)
- func (ls *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 (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 (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 (m *StructMap[K, V]) SetManagedValue(val map[K]V)
- func (p *StructMap) SetReadOnly(readonly bool)
- func (m *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 (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)
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 read-only preference.ErrReadOnly =errors.New("cannot modify a read-only preference"))
Functions¶
This section is empty.
Types¶
typeBasicType¶
type BasicType interface {~bool |constraints.Integer |constraints.Float |constraints.Complex | ~string}BasicType is a constraint that allows types whose underlying type is a predeclaredboolean, numeric, or string type.
typeImmutableType¶
ImmutableType is a constraint that allows [BasicType]s and certain well-known immutable types.
typeItem¶
type Item[Tany] 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 theviews.ViewCloner interface.
funcItemWithOpts¶
ItemWithOpts returns an unconfiguredItem with the specifiedOptions.
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 returnsErrManaged if p is a managed preference,andErrReadOnly 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 callItem.Clone if T contains pointersbut does not implementviews.Cloner.
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 usedinstead 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)MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.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 valueand marks the preference as managed.
func (*Item)SetReadOnly¶
func (p *Item) SetReadOnly(readonlybool)
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
func (*Item)UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*Item)UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
typeItemView¶
type ItemView[Tviews.ViewCloner[T, V], Vviews.StructView[T]] struct {// contains filtered or unexported fields}
ItemView is a read-only view of anItem[T], where T is a mutable typeimplementingviews.ViewCloner.
funcItemViewOf¶
func ItemViewOf[Tviews.ViewCloner[T, V], Vviews.StructView[T]](i *Item[T])ItemView[T, V]
ItemViewOf returns a read-only view of i.It is used bytailscale.com/cmd/viewer.
func (ItemView[T, V])AsStruct¶
AsStruct implementsviews.StructView by returning a clone of the preferencewhich aliases no memory with the original.
func (ItemView[T, V])DefaultValue¶
func (ivItemView[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])MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*ItemView[T, V])UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*ItemView[T, V])UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
typeList¶
type List[TImmutableType] struct {// contains filtered or unexported fields}
List is a preference type that holds zero or more values of anImmutableType T.
funcListOf¶
func ListOf[TImmutableType](v []T, opts ...Options)List[T]
ListOf returns aList configured with the specified value andOptions.
funcListWithOpts¶
func ListWithOpts[TImmutableType](opts ...Options)List[T]
ListWithOpts returns an unconfiguredList with the specifiedOptions.
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
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)MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*List)SetDefaultValue¶
func (p *List) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*List[T])SetManagedValue¶
func (ls *List[T]) SetManagedValue(val []T)
SetManagedValue configures the preference with the specified valueand marks the preference as managed.
func (*List)SetReadOnly¶
func (p *List) SetReadOnly(readonlybool)
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
func (*List)UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*List)UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.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.
typeListView¶
type ListView[TImmutableType] struct {// contains filtered or unexported fields}
ListView is a read-only view of aList.
func (ListView[T])AsStruct¶
AsStruct implementsviews.StructView by returning a clone of theListwhich 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])MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*ListView[T])UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*ListView[T])UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
typeMap¶
type Map[KMapKeyType, VImmutableType] struct {// contains filtered or unexported fields}
Map is a preference type that holds immutable key-value pairs.
funcMapOf¶
func MapOf[KMapKeyType, VImmutableType](v map[K]V, opts ...Options)Map[K, V]
MapOf returns a map configured with the specified value andOptions.
funcMapWithOpts¶
func MapWithOpts[KMapKeyType, VImmutableType](opts ...Options)Map[K, V]
MapWithOpts returns an unconfiguredMap with the specifiedOptions.
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
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)MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.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 valueand marks the preference as managed.
func (*Map)SetReadOnly¶
func (p *Map) SetReadOnly(readonlybool)
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
func (*Map)UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*Map)UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.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.
typeMapKeyType¶
MapKeyType is a constraint allowing types that can be used asMap andStructMap keys.To satisfy this requirement, a type must be comparable and must encode as a JSON string.Seejsonv2.Marshal for more details.
typeMapView¶
type MapView[KMapKeyType, VImmutableType] struct {// contains filtered or unexported fields}
MapView is a read-only view of aMap.
func (MapView[K, V])AsStruct¶
AsStruct implementsviews.StructView by returning a clone of theMapwhich 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])MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.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¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
typeOptions¶
type Options func(s *metadata)
Options are used to configure additional parameters of a preference.
typeStructList¶
StructList is a preference type that holds zero or more potentially mutable struct values.
funcStructListOf¶
func StructListOf[Tviews.Cloner[T]](v []T, opts ...Options)StructList[T]
StructListOf returns aStructList configured with the specified value andOptions.
funcStructListWithOpts¶
func StructListWithOpts[Tviews.Cloner[T]](opts ...Options)StructList[T]
StructListWithOpts returns an unconfiguredStructList with the specifiedOptions.
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
func (StructList[T])Clone¶
func (lsStructList[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 (lsStructList[T]) Equal(l2StructList[T])bool
Equal reports whether l and l2 are equal.If the template type T implements an Equal(T) bool method, it will be usedinstead 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)MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*StructList)SetDefaultValue¶
func (p *StructList) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*StructList[T])SetManagedValue¶
func (ls *StructList[T]) SetManagedValue(val []T)
SetManagedValue configures the preference with the specified valueand marks the preference as managed.
func (*StructList)SetReadOnly¶
func (p *StructList) SetReadOnly(readonlybool)
SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.
func (*StructList[T])SetValue¶
func (ls *StructList[T]) SetValue(val []T)error
SetValue configures the preference with the specified value.It fails and returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
func (*StructList)UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*StructList)UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
typeStructListView¶
type StructListView[Tviews.ViewCloner[T, V], Vviews.StructView[T]] struct {// contains filtered or unexported fields}
StructListView is a read-only view of aStructList.
funcStructListViewOf¶
func StructListViewOf[Tviews.ViewCloner[T, V], Vviews.StructView[T]](ls *StructList[T])StructListView[T, V]
StructListViewOf returns a read-only view of l.It is used bytailscale.com/cmd/viewer.
func (StructListView[T, V])AsStruct¶
func (lvStructListView[T, V]) AsStruct() *StructList[T]
AsStruct implementsviews.StructView by returning a clone of the preferencewhich aliases no memory with the original.
func (StructListView[T, V])DefaultValue¶
func (lvStructListView[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 (lvStructListView[T, V]) Equal(lv2StructListView[T, V])bool
Equal reports whether iv and iv2 are equal.
func (StructListView[T, V])IsManaged¶
func (lvStructListView[T, V]) IsManaged()bool
IsManaged reports whether the preference is managed via MDM, Group Policy, or similar means.
func (StructListView[T, V])IsReadOnly¶
func (lvStructListView[T, V]) IsReadOnly()bool
IsReadOnly reports whether the preference is read-only and cannot be changed by user.
func (StructListView[T, V])IsSet¶
func (lvStructListView[T, V]) IsSet()bool
IsSet reports whether the preference has a value set.
func (StructListView[T, V])MarshalJSON¶
func (lvStructListView[T, V]) MarshalJSON() ([]byte,error)
MarshalJSON implements [json.Marshaler].
func (StructListView[T, V])MarshalJSONTo¶added inv1.82.0
func (lvStructListView[T, V]) MarshalJSONTo(out *jsontext.Encoder)error
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*StructListView[T, V])UnmarshalJSON¶
func (lv *StructListView[T, V]) UnmarshalJSON(b []byte)error
UnmarshalJSON implements [json.Unmarshaler].
func (*StructListView[T, V])UnmarshalJSONFrom¶added inv1.82.0
func (lv *StructListView[T, V]) UnmarshalJSONFrom(in *jsontext.Decoder)error
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
func (StructListView[T, V])Valid¶
func (lvStructListView[T, V]) Valid()bool
Valid reports whether the underlyingStructList is non-nil.
func (StructListView[T, V])Value¶
func (lvStructListView[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.
typeStructMap¶
type StructMap[KMapKeyType, Vviews.Cloner[V]] struct {// contains filtered or unexported fields}
StructMap is a preference type that holds potentially mutable key-value pairs.
funcStructMapOf¶
func StructMapOf[KMapKeyType, Vviews.Cloner[V]](v map[K]V, opts ...Options)StructMap[K, V]
StructMapOf returns aStructMap configured with the specified value andOptions.
funcStructMapWithOpts¶
func StructMapWithOpts[KMapKeyType, Vviews.Cloner[V]](opts ...Options)StructMap[K, V]
StructMapWithOpts returns an unconfiguredStructMap with the specifiedOptions.
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 returnsErrManaged if p is a managed preference,andErrReadOnly 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 usedinstead 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)MarshalJSONTo¶added inv1.82.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*StructMap)SetDefaultValue¶
func (p *StructMap) SetDefaultValue(def T)
SetDefaultValue sets the default value of p.
func (*StructMap[K, V])SetManagedValue¶
func (m *StructMap[K, V]) SetManagedValue(val map[K]V)
SetManagedValue configures the preference with the specified valueand marks the preference as managed.
func (*StructMap)SetReadOnly¶
func (p *StructMap) SetReadOnly(readonlybool)
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 returnsErrManaged if p is a managed preference,andErrReadOnly if p is a read-only preference.
func (*StructMap)UnmarshalJSON¶
UnmarshalJSON implements [json.Unmarshaler].
func (*StructMap)UnmarshalJSONFrom¶added inv1.82.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
typeStructMapView¶
type StructMapView[KMapKeyType, Tviews.ViewCloner[T, V], Vviews.StructView[T]] struct {// contains filtered or unexported fields}
StructMapView is a read-only view of aStructMap.
funcStructMapViewOf¶
func StructMapViewOf[KMapKeyType, Tviews.ViewCloner[T, V], Vviews.StructView[T]](m *StructMap[K, T])StructMapView[K, T, V]
StructMapViewOf returns a read-only view of m.It is used bytailscale.com/cmd/viewer.
func (StructMapView[K, T, V])AsStruct¶
func (mvStructMapView[K, T, V]) AsStruct() *StructMap[K, T]
AsStruct implementsviews.StructView by returning a clone of the preferencewhich aliases no memory with the original.
func (StructMapView[K, T, V])DefaultValue¶
func (mvStructMapView[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 (mvStructMapView[K, T, V]) Equal(mv2StructMapView[K, T, V])bool
Equal reports whether mv and mv2 are equal.
func (StructMapView[K, T, V])IsManaged¶
func (mvStructMapView[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 (mvStructMapView[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 (mvStructMapView[K, T, V]) IsSet()bool
IsSet reports whether the preference has a value set.
func (StructMapView[K, T, V])MarshalJSON¶
func (mvStructMapView[K, T, V]) MarshalJSON() ([]byte,error)
MarshalJSON implements [json.Marshaler].
func (StructMapView[K, T, V])MarshalJSONTo¶added inv1.82.0
func (mvStructMapView[K, T, V]) MarshalJSONTo(out *jsontext.Encoder)error
MarshalJSONTo implementsjsonv2.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¶added inv1.82.0
func (mv *StructMapView[K, T, V]) UnmarshalJSONFrom(in *jsontext.Decoder)error
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
func (StructMapView[K, T, V])Valid¶
func (mvStructMapView[K, T, V]) Valid()bool
Valid reports whether the underlyingStructMap is non-nil.
func (StructMapView[K, T, V])Value¶
func (mvStructMapView[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.
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. |