Help us shape the future of Go! Take the 2026 Go Developer Survey

prefs

package
v1.104.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 13 Imported by: 1

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

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

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

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.

type Item

type Item[T any] struct {
	// contains filtered or unexported fields
}

Item is a single preference item that can be configured. T must either be an immutable type or implement the views.ViewCloner interface.

func ItemOf

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

ItemOf returns an Item configured with the specified value and Options.

func ItemWithOpts

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

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

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

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

func (i Item[T]) Equal(i2 Item[T]) bool

Equal reports whether i and i2 are equal. If the template type T implements an Equal(T) bool method, it will be used instead of the == operator for value comparison. If T is not comparable, it reports false.

func (Item) IsManaged

func (p Item) IsManaged() bool

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

func (Item) IsReadOnly

func (p Item) IsReadOnly() bool

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

func (Item) IsSet

func (p Item) IsSet() bool

IsSet reports whether p has a value set.

func (Item) MarshalJSON

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

MarshalJSON implements [json.Marshaler].

func (Item) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*Item) SetDefaultValue

func (p *Item) SetDefaultValue(def T)

SetDefaultValue sets the default value of p.

func (*Item[T]) SetManagedValue

func (i *Item[T]) SetManagedValue(val T)

SetManagedValue configures the preference with the specified value and marks the preference as managed.

func (*Item) SetReadOnly

func (p *Item) SetReadOnly(readonly bool)

SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.

func (*Item[T]) SetValue

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

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

UnmarshalJSON implements [json.Unmarshaler].

func (*Item) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (Item) Value

func (p Item) Value() T

Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.

func (Item) ValueOk

func (p Item) ValueOk() (val T, ok bool)

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

type ItemView

type ItemView[T views.ViewCloner[T, V], V views.StructView[T]] struct {
	// contains filtered or unexported fields
}

ItemView is a read-only view of an Item[T], where T is a mutable type implementing views.ViewCloner.

func ItemViewOf

func ItemViewOf[T views.ViewCloner[T, V], V views.StructView[T]](i *Item[T]) ItemView[T, V]

ItemViewOf returns a read-only view of i. It is used by tailscale.com/cmd/viewer.

func (ItemView[T, V]) AsStruct

func (iv ItemView[T, V]) AsStruct() *Item[T]

AsStruct implements views.StructView by returning a clone of the preference which aliases no memory with the original.

func (ItemView[T, V]) DefaultValue

func (iv ItemView[T, V]) DefaultValue() V

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

func (ItemView[T, V]) Equal

func (iv ItemView[T, V]) Equal(iv2 ItemView[T, V]) bool

Equal reports whether iv and iv2 are equal.

func (ItemView[T, V]) IsManaged

func (iv ItemView[T, V]) IsManaged() bool

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

func (ItemView[T, V]) IsReadOnly

func (iv ItemView[T, V]) IsReadOnly() bool

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

func (ItemView[T, V]) IsSet

func (iv ItemView[T, V]) IsSet() bool

IsSet reports whether the preference has a value set.

func (ItemView[T, V]) MarshalJSON

func (iv ItemView[T, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements [json.Marshaler].

func (ItemView[T, V]) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*ItemView[T, V]) UnmarshalJSON

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

UnmarshalJSON implements [json.Unmarshaler].

func (*ItemView[T, V]) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (ItemView[T, V]) Valid

func (iv ItemView[T, V]) Valid() bool

Valid reports whether the underlying Item is non-nil.

func (ItemView[T, V]) Value

func (iv ItemView[T, V]) Value() V

Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.

func (ItemView[T, V]) ValueOk

func (iv ItemView[T, V]) ValueOk() (val V, ok bool)

ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.

type List

type List[T ImmutableType] struct {
	// contains filtered or unexported fields
}

List is a preference type that holds zero or more values of an ImmutableType T.

func ListOf

func ListOf[T ImmutableType](v []T, opts ...Options) List[T]

ListOf returns a List configured with the specified value and Options.

func ListWithOpts

func ListWithOpts[T ImmutableType](opts ...Options) List[T]

ListWithOpts returns an unconfigured List with the specified Options.

func (*List) ClearManaged

func (p *List) ClearManaged()

ClearManaged clears the managed flag of the preference without altering its value.

func (*List) ClearValue

func (p *List) ClearValue() error

ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.

func (List[T]) Clone

func (ls List[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 (ls List[T]) Equal(l2 List[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) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*List) SetDefaultValue

func (p *List) SetDefaultValue(def T)

SetDefaultValue sets the default value of p.

func (*List[T]) SetManagedValue

func (ls *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

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

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

UnmarshalJSON implements [json.Unmarshaler].

func (*List) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (List) Value

func (p List) Value() T

Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.

func (List) ValueOk

func (p List) ValueOk() (val T, ok bool)

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

func (*List[T]) View

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

View returns a read-only view of l.

type ListView

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

ListView is a read-only view of a List.

func (ListView[T]) AsStruct

func (lv ListView[T]) AsStruct() *List[T]

AsStruct implements views.StructView by returning a clone of the List which aliases no memory with the original.

func (ListView[T]) DefaultValue

func (lv ListView[T]) DefaultValue() views.Slice[T]

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

func (ListView[T]) Equal

func (lv ListView[T]) Equal(lv2 ListView[T]) bool

Equal reports whether lv and lv2 are equal.

func (ListView[T]) IsManaged

func (lv ListView[T]) IsManaged() bool

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

func (ListView[T]) IsReadOnly

func (lv ListView[T]) IsReadOnly() bool

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

func (ListView[T]) IsSet

func (lv ListView[T]) IsSet() bool

IsSet reports whether the preference has a value set.

func (ListView[T]) MarshalJSON

func (lv ListView[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements [json.Marshaler].

func (ListView[T]) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*ListView[T]) UnmarshalJSON

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

UnmarshalJSON implements [json.Unmarshaler].

func (*ListView[T]) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (ListView[T]) Valid

func (lv ListView[T]) Valid() bool

Valid reports whether the underlying List is non-nil.

func (ListView[T]) Value

func (lv ListView[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 (lv ListView[T]) ValueOk() (val views.Slice[T], ok bool)

ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.

type Map

type Map[K MapKeyType, V ImmutableType] struct {
	// contains filtered or unexported fields
}

Map is a preference type that holds immutable key-value pairs.

func MapOf

func MapOf[K MapKeyType, V ImmutableType](v map[K]V, opts ...Options) Map[K, V]

MapOf returns a map configured with the specified value and Options.

func MapWithOpts

func MapWithOpts[K MapKeyType, V ImmutableType](opts ...Options) Map[K, V]

MapWithOpts returns an unconfigured Map with the specified Options.

func (*Map) ClearManaged

func (p *Map) ClearManaged()

ClearManaged clears the managed flag of the preference without altering its value.

func (*Map) ClearValue

func (p *Map) ClearValue() error

ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.

func (Map[K, V]) Clone

func (m Map[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 (m Map[K, V]) Equal(m2 Map[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) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*Map) SetDefaultValue

func (p *Map) SetDefaultValue(def T)

SetDefaultValue sets the default value of p.

func (*Map) SetManagedValue

func (p *Map) SetManagedValue(val T)

SetManagedValue configures the preference with the specified value and marks the preference as managed.

func (*Map) SetReadOnly

func (p *Map) SetReadOnly(readonly bool)

SetReadOnly sets the read-only status of p, preventing changes by a user if set to true.

func (*Map) SetValue

func (p *Map) SetValue(val T) error

SetValue configures the preference with the specified value. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.

func (*Map) UnmarshalJSON

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

UnmarshalJSON implements [json.Unmarshaler].

func (*Map) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (Map) Value

func (p Map) Value() T

Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.

func (Map) ValueOk

func (p Map) ValueOk() (val T, ok bool)

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

func (*Map[K, V]) View

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

View returns a read-only view of m.

type MapKeyType

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

MapKeyType is a constraint allowing types that can be used as Map and StructMap keys. To satisfy this requirement, a type must be comparable and must encode as a JSON string. See jsonv2.Marshal for more details.

type MapView

type MapView[K MapKeyType, V ImmutableType] struct {
	// contains filtered or unexported fields
}

MapView is a read-only view of a Map.

func (MapView[K, V]) AsStruct

func (mv MapView[K, V]) AsStruct() *Map[K, V]

AsStruct implements views.StructView by returning a clone of the Map which aliases no memory with the original.

func (MapView[K, V]) DefaultValue

func (mv MapView[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 (mv MapView[K, V]) Equal(mv2 MapView[K, V]) bool

Equal reports whether mv and mv2 are equal.

func (MapView[K, V]) IsSet

func (mv MapView[K, V]) IsSet() bool

IsSet reports whether the preference has a value set.

func (MapView[K, V]) Managed

func (mv MapView[K, V]) Managed() bool

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

func (MapView[K, V]) MarshalJSON

func (mv MapView[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements [json.Marshaler].

func (MapView[K, V]) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (MapView[K, V]) ReadOnly

func (mv MapView[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]) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (MapView[K, V]) Valid

func (mv MapView[K, V]) Valid() bool

Valid reports whether the underlying Map is non-nil.

func (MapView[K, V]) Value

func (mv MapView[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 (mv MapView[K, V]) ValueOk() (val views.Map[K, V], ok bool)

ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.

type Options

type Options func(s *metadata)

Options are used to configure additional parameters of a preference.

var (
	// ReadOnly is an option that marks preference as read-only.
	ReadOnly Options = markReadOnly
	// Managed is an option that marks preference as managed.
	Managed Options = markManaged
)

type StructList

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

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 (ls 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 (ls StructList[T]) Equal(l2 StructList[T]) bool

Equal reports whether l and l2 are equal. If the template type T implements an Equal(T) bool method, it will be used instead of the == operator for value comparison. It panics if T is not comparable.

func (StructList) IsManaged

func (p StructList) IsManaged() bool

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

func (StructList) IsReadOnly

func (p StructList) IsReadOnly() bool

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

func (StructList) IsSet

func (p StructList) IsSet() bool

IsSet reports whether p has a value set.

func (StructList) MarshalJSON

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

MarshalJSON implements [json.Marshaler].

func (StructList) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*StructList) SetDefaultValue

func (p *StructList) SetDefaultValue(def T)

SetDefaultValue sets the default value of p.

func (*StructList[T]) SetManagedValue

func (ls *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 (ls *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

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

UnmarshalJSON implements [json.Unmarshaler].

func (*StructList) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (StructList) Value

func (p StructList) Value() T

Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.

func (StructList) ValueOk

func (p StructList) ValueOk() (val T, ok bool)

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

type StructListView

type StructListView[T views.ViewCloner[T, V], V views.StructView[T]] struct {
	// contains filtered or unexported fields
}

StructListView is a read-only view of a StructList.

func StructListViewOf

func StructListViewOf[T views.ViewCloner[T, V], V views.StructView[T]](ls *StructList[T]) StructListView[T, V]

StructListViewOf returns a read-only view of l. It is used by tailscale.com/cmd/viewer.

func (StructListView[T, V]) AsStruct

func (lv StructListView[T, V]) AsStruct() *StructList[T]

AsStruct implements views.StructView by returning a clone of the preference which aliases no memory with the original.

func (StructListView[T, V]) DefaultValue

func (lv StructListView[T, V]) DefaultValue() views.SliceView[T, V]

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

func (StructListView[T, V]) Equal

func (lv StructListView[T, V]) Equal(lv2 StructListView[T, V]) bool

Equal reports whether iv and iv2 are equal.

func (StructListView[T, V]) IsManaged

func (lv StructListView[T, V]) IsManaged() bool

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

func (StructListView[T, V]) IsReadOnly

func (lv StructListView[T, V]) IsReadOnly() bool

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

func (StructListView[T, V]) IsSet

func (lv StructListView[T, V]) IsSet() bool

IsSet reports whether the preference has a value set.

func (StructListView[T, V]) MarshalJSON

func (lv StructListView[T, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements [json.Marshaler].

func (StructListView[T, V]) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*StructListView[T, V]) UnmarshalJSON

func (lv *StructListView[T, V]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements [json.Unmarshaler].

func (*StructListView[T, V]) UnmarshalJSONFrom added in v1.82.0

func (lv *StructListView[T, V]) UnmarshalJSONFrom(in *jsontext.Decoder) error

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (StructListView[T, V]) Valid

func (lv StructListView[T, V]) Valid() bool

Valid reports whether the underlying StructList is non-nil.

func (StructListView[T, V]) Value

func (lv StructListView[T, V]) Value() views.SliceView[T, V]

Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.

func (StructListView[T, V]) ValueOk

func (lv StructListView[T, V]) ValueOk() (val views.SliceView[T, V], ok bool)

ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.

type StructMap

type StructMap[K MapKeyType, V views.Cloner[V]] struct {
	// contains filtered or unexported fields
}

StructMap is a preference type that holds potentially mutable key-value pairs.

func StructMapOf

func StructMapOf[K MapKeyType, V views.Cloner[V]](v map[K]V, opts ...Options) StructMap[K, V]

StructMapOf returns a StructMap configured with the specified value and Options.

func StructMapWithOpts

func StructMapWithOpts[K MapKeyType, V views.Cloner[V]](opts ...Options) StructMap[K, V]

StructMapWithOpts returns an unconfigured StructMap with the specified Options.

func (*StructMap) ClearManaged

func (p *StructMap) ClearManaged()

ClearManaged clears the managed flag of the preference without altering its value.

func (*StructMap) ClearValue

func (p *StructMap) ClearValue() error

ClearValue resets the preference to an unconfigured state. It fails and returns ErrManaged if p is a managed preference, and ErrReadOnly if p is a read-only preference.

func (StructMap[K, V]) Clone

func (m StructMap[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 (m StructMap[K, V]) Equal(m2 StructMap[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 used instead of the == operator for value comparison. It panics if T is not comparable.

func (StructMap) IsManaged

func (p StructMap) IsManaged() bool

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

func (StructMap) IsReadOnly

func (p StructMap) IsReadOnly() bool

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

func (StructMap) IsSet

func (p StructMap) IsSet() bool

IsSet reports whether p has a value set.

func (StructMap) MarshalJSON

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

MarshalJSON implements [json.Marshaler].

func (StructMap) MarshalJSONTo added in v1.82.0

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

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*StructMap) SetDefaultValue

func (p *StructMap) SetDefaultValue(def T)

SetDefaultValue sets the default value of p.

func (*StructMap[K, V]) SetManagedValue

func (m *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

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

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

UnmarshalJSON implements [json.Unmarshaler].

func (*StructMap) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

func (StructMap) Value

func (p StructMap) Value() T

Value returns the value of p if the preference has a value set. Otherwise, it returns its default value.

func (StructMap) ValueOk

func (p StructMap) ValueOk() (val T, ok bool)

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

type StructMapView

type StructMapView[K MapKeyType, T views.ViewCloner[T, V], V views.StructView[T]] struct {
	// contains filtered or unexported fields
}

StructMapView is a read-only view of a StructMap.

func StructMapViewOf

func StructMapViewOf[K MapKeyType, T views.ViewCloner[T, V], V views.StructView[T]](m *StructMap[K, T]) StructMapView[K, T, V]

StructMapViewOf returns a read-only view of m. It is used by tailscale.com/cmd/viewer.

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

func (mv StructMapView[K, T, V]) AsStruct() *StructMap[K, T]

AsStruct implements views.StructView by returning a clone of the preference which aliases no memory with the original.

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

func (mv StructMapView[K, T, V]) DefaultValue() views.MapFn[K, T, V]

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

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

func (mv StructMapView[K, T, V]) Equal(mv2 StructMapView[K, T, V]) bool

Equal reports whether mv and mv2 are equal.

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

func (mv StructMapView[K, T, V]) IsManaged() bool

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

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

func (mv StructMapView[K, T, V]) IsReadOnly() bool

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

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

func (mv StructMapView[K, T, V]) IsSet() bool

IsSet reports whether the preference has a value set.

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

func (mv StructMapView[K, T, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements [json.Marshaler].

func (StructMapView[K, T, V]) MarshalJSONTo added in v1.82.0

func (mv StructMapView[K, T, V]) MarshalJSONTo(out *jsontext.Encoder) error

MarshalJSONTo implements jsonv2.MarshalerTo.

func (*StructMapView[K, T, V]) UnmarshalJSON

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

UnmarshalJSON implements [json.Unmarshaler].

func (*StructMapView[K, T, V]) UnmarshalJSONFrom added in v1.82.0

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

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

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

func (mv StructMapView[K, T, V]) Valid() bool

Valid reports whether the underlying StructMap is non-nil.

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

func (mv StructMapView[K, T, V]) Value() views.MapFn[K, T, V]

Value returns a read-only view of the value if the preference has a value set. Otherwise, it returns a read-only view of its default value.

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

func (mv StructMapView[K, T, V]) ValueOk() (val views.MapFn[K, T, V], ok bool)

ValueOk returns a read-only view of the value and true if the preference has a value set. Otherwise, it returns an invalid view and false.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL