Movatterモバイル変換


[0]ホーム

URL:


prefs

package
v1.92.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:14Imported by:1

Details

Repository

github.com/tailscale/tailscale

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

Constants

This section is empty.

Variables

View Source
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

BasicType is a constraint that allows types whose underlying type is a predeclaredboolean, numeric, or string type.

typeImmutableType

type ImmutableType interface {BasicType |time.Time |netip.Addr |netip.Prefix |netip.AddrPort}

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.

funcItemOf

func ItemOf[Tany](v T, opts ...Options)Item[T]

ItemOf returns anItem configured with the specified value andOptions.

funcItemWithOpts

func ItemWithOpts[Tany](opts ...Options)Item[T]

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

func (iItem[T]) Clone() *Item[T]

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)DefaultValue

func (p Item) DefaultValue() T

DefaultValue returns the default value of p.

func (Item[T])Equal

func (iItem[T]) Equal(i2Item[T])bool

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)IsSet

func (p Item) IsSet()bool

IsSet reports whether p has a value set.

func (Item)MarshalJSON

func (p Item) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (Item)MarshalJSONToadded inv1.82.0

func (p Item) MarshalJSONTo(out *jsontext.Encoder)error

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

func (i *Item[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 (*Item)UnmarshalJSON

func (p *Item) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*Item)UnmarshalJSONFromadded inv1.82.0

func (p *Item) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.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, okbool)

ValueOk returns the value of p and true if the preference has a value set.Otherwise, it returns its default value and false.

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

func (ivItemView[T, V]) AsStruct() *Item[T]

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])Equal

func (ivItemView[T, V]) Equal(iv2ItemView[T, V])bool

Equal reports whether iv and iv2 are equal.

func (ItemView[T, V])IsManaged

func (ivItemView[T, V]) IsManaged()bool

IsManaged reports whether the preference is managed via MDM, Group Policy, or similar means.

func (ItemView[T, V])IsReadOnly

func (ivItemView[T, V]) IsReadOnly()bool

IsReadOnly reports whether the preference is read-only and cannot be changed by user.

func (ItemView[T, V])IsSet

func (ivItemView[T, V]) IsSet()bool

IsSet reports whether the preference has a value set.

func (ItemView[T, V])MarshalJSON

func (ivItemView[T, V]) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (ItemView[T, V])MarshalJSONToadded inv1.82.0

func (ivItemView[T, V]) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (*ItemView[T, V])UnmarshalJSON

func (iv *ItemView[T, V]) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*ItemView[T, V])UnmarshalJSONFromadded inv1.82.0

func (iv *ItemView[T, V]) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

func (ItemView[T, V])Valid

func (ivItemView[T, V]) Valid()bool

Valid reports whether the underlyingItem is non-nil.

func (ItemView[T, V])Value

func (ivItemView[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

func (ivItemView[T, V]) ValueOk() (val V, okbool)

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.

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[T])Clone

func (lsList[T]) Clone() *List[T]

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

func (lsList[T]) Equal(l2List[T])bool

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

func (p List) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (List)MarshalJSONToadded inv1.82.0

func (p List) MarshalJSONTo(out *jsontext.Encoder)error

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

func (ls *List[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 (*List)UnmarshalJSON

func (p *List) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*List)UnmarshalJSONFromadded inv1.82.0

func (p *List) UnmarshalJSONFrom(in *jsontext.Decoder)error

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.

func (List)ValueOk

func (p List) ValueOk() (val T, okbool)

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

func (ls *List[T]) View()ListView[T]

View returns a read-only view of l.

typeListView

type ListView[TImmutableType] struct {// contains filtered or unexported fields}

ListView is a read-only view of aList.

func (ListView[T])AsStruct

func (lvListView[T]) AsStruct() *List[T]

AsStruct implementsviews.StructView by returning a clone of theListwhich aliases no memory with the original.

func (ListView[T])DefaultValue

func (lvListView[T]) DefaultValue()views.Slice[T]

DefaultValue returns a read-only view of the default value of the preference.

func (ListView[T])Equal

func (lvListView[T]) Equal(lv2ListView[T])bool

Equal reports whether lv and lv2 are equal.

func (ListView[T])IsManaged

func (lvListView[T]) IsManaged()bool

IsManaged reports whether the preference is managed via MDM, Group Policy, or similar means.

func (ListView[T])IsReadOnly

func (lvListView[T]) IsReadOnly()bool

IsReadOnly reports whether the preference is read-only and cannot be changed by user.

func (ListView[T])IsSet

func (lvListView[T]) IsSet()bool

IsSet reports whether the preference has a value set.

func (ListView[T])MarshalJSON

func (lvListView[T]) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (ListView[T])MarshalJSONToadded inv1.82.0

func (lvListView[T]) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (*ListView[T])UnmarshalJSON

func (lv *ListView[T]) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*ListView[T])UnmarshalJSONFromadded inv1.82.0

func (lv *ListView[T]) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

func (ListView[T])Valid

func (lvListView[T]) Valid()bool

Valid reports whether the underlyingList is non-nil.

func (ListView[T])Value

func (lvListView[T]) Value()views.Slice[T]

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

func (lvListView[T]) ValueOk() (valviews.Slice[T], okbool)

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.

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[K, V])Clone

func (mMap[K, V]) Clone() *Map[K, V]

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

func (mMap[K, V]) Equal(m2Map[K, V])bool

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

func (p Map) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (Map)MarshalJSONToadded inv1.82.0

func (p Map) MarshalJSONTo(out *jsontext.Encoder)error

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

func (p *Map) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*Map)UnmarshalJSONFromadded inv1.82.0

func (p *Map) UnmarshalJSONFrom(in *jsontext.Decoder)error

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.

func (Map)ValueOk

func (p Map) ValueOk() (val T, okbool)

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

func (m *Map[K, V]) View()MapView[K, V]

View returns a read-only view of m.

typeMapKeyType

type MapKeyType interface {~string |constraints.Integer |netip.Addr |netip.Prefix |netip.AddrPort}

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

func (mvMapView[K, V]) AsStruct() *Map[K, V]

AsStruct implementsviews.StructView by returning a clone of theMapwhich aliases no memory with the original.

func (MapView[K, V])DefaultValue

func (mvMapView[K, V]) DefaultValue()views.Map[K, V]

DefaultValue returns a read-only view of the default value of the preference.

func (MapView[K, V])Equal

func (mvMapView[K, V]) Equal(mv2MapView[K, V])bool

Equal reports whether mv and mv2 are equal.

func (MapView[K, V])IsSet

func (mvMapView[K, V]) IsSet()bool

IsSet reports whether the preference has a value set.

func (MapView[K, V])Managed

func (mvMapView[K, V]) Managed()bool

Managed reports whether the preference is managed via MDM, Group Policy, or similar means.

func (MapView[K, V])MarshalJSON

func (mvMapView[K, V]) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (MapView[K, V])MarshalJSONToadded inv1.82.0

func (mvMapView[K, V]) MarshalJSONTo(out *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (MapView[K, V])ReadOnly

func (mvMapView[K, V]) ReadOnly()bool

ReadOnly reports whether the preference is read-only and cannot be changed by user.

func (*MapView[K, V])UnmarshalJSON

func (mv *MapView[K, V]) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*MapView[K, V])UnmarshalJSONFromadded inv1.82.0

func (mv *MapView[K, V]) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

func (MapView[K, V])Valid

func (mvMapView[K, V]) Valid()bool

Valid reports whether the underlyingMap is non-nil.

func (MapView[K, V])Value

func (mvMapView[K, V]) Value()views.Map[K, 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 (MapView[K, V])ValueOk

func (mvMapView[K, V]) ValueOk() (valviews.Map[K, V], okbool)

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.

typeOptions

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.ReadOnlyOptions = markReadOnly// Managed is an option that marks preference as managed.ManagedOptions = markManaged)

typeStructList

type StructList[Tviews.Cloner[T]] struct {// contains filtered or unexported fields}

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)IsSet

func (p StructList) IsSet()bool

IsSet reports whether p has a value set.

func (StructList)MarshalJSON

func (p StructList) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (StructList)MarshalJSONToadded inv1.82.0

func (p StructList) MarshalJSONTo(out *jsontext.Encoder)error

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

func (p *StructList) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*StructList)UnmarshalJSONFromadded inv1.82.0

func (p *StructList) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.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, okbool)

ValueOk returns the value of p and true if the preference has a value set.Otherwise, it returns its default value and false.

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])MarshalJSONToadded 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])UnmarshalJSONFromadded 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.

func (StructListView[T, V])ValueOk

func (lvStructListView[T, V]) ValueOk() (valviews.SliceView[T, V], okbool)

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.

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[K, V])Clone

func (mStructMap[K, V]) Clone() *StructMap[K, V]

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

func (mStructMap[K, V]) Equal(m2StructMap[K, V])bool

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)IsSet

func (p StructMap) IsSet()bool

IsSet reports whether p has a value set.

func (StructMap)MarshalJSON

func (p StructMap) MarshalJSON() ([]byte,error)

MarshalJSON implements [json.Marshaler].

func (StructMap)MarshalJSONToadded inv1.82.0

func (p StructMap) MarshalJSONTo(out *jsontext.Encoder)error

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

func (m *StructMap[K, V]) SetValue(val map[K]V)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 (*StructMap)UnmarshalJSON

func (p *StructMap) UnmarshalJSON(b []byte)error

UnmarshalJSON implements [json.Unmarshaler].

func (*StructMap)UnmarshalJSONFromadded inv1.82.0

func (p *StructMap) UnmarshalJSONFrom(in *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.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, okbool)

ValueOk returns the value of p and true if the preference has a value set.Otherwise, it returns its default value and false.

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])MarshalJSONToadded 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])UnmarshalJSONFromadded 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.

func (StructMapView[K, T, V])ValueOk

func (mvStructMapView[K, T, V]) ValueOk() (valviews.MapFn[K, T, V], okbool)

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

View all Source files

Directories

PathSynopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp