Movatterモバイル変換


[0]ホーム

URL:


views

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:13Imported by:58

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package views provides read-only accessors for commonly usedvalue types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcAppendStringsadded inv1.66.0

func AppendStrings[Tfmt.Stringer](dst []string, vSlice[T]) []string

AppendStrings appends the string representation of each element in v to dst.

funcContainsPointersadded inv1.72.0

func ContainsPointers[Tany]()bool

ContainsPointers reports whether T contains any pointers,either explicitly or implicitly.It has special handling for some types that contain pointersthat we know are free from memory aliasing/mutation concerns.

funcMapViewsEqualadded inv1.80.0

func MapViewsEqual[K, Vcomparable](a, bMap[K, V])bool

MapViewsEqual returns whether the two given [Map]s are equal. Both K and Vmust be comparable; if V is non-comparable, useMapViewsEqualFunc instead.

funcMapViewsEqualFuncadded inv1.80.0

func MapViewsEqualFunc[Kcomparable, V1, V2any](aMap[K, V1], bMap[K, V2], eq func(V1, V2)bool)bool

MapViewsEqualFunc returns whether the two given [Map]s are equal, using thegiven function to compare two values.

funcSliceContainsadded inv1.30.0

func SliceContains[Tcomparable](vSlice[T], e T)bool

SliceContains reports whether v contains element e.

As it runs in O(n) time, use with care.

funcSliceEqualadded inv1.50.0

func SliceEqual[Tcomparable](a, bSlice[T])bool

SliceEqual is like the standard library's slices.Equal, but for two views.

funcSliceEqualAnyOrderadded inv1.36.0

func SliceEqualAnyOrder[Tcomparable](a, bSlice[T])bool

SliceEqualAnyOrder reports whether a and b contain the same elements, regardless of order.The underlying slices for a and b can be nil.

funcSliceEqualAnyOrderFuncadded inv1.80.0

func SliceEqualAnyOrderFunc[Tany, Vcomparable](a, bSlice[T], cmp func(T) V)bool

SliceEqualAnyOrderFunc reports whether a and b contain the same elements,regardless of order. The underlying slices for a and b can be nil.

The provided function should return a comparable value for each element.

funcSliceMaxadded inv1.88.0

func SliceMax[Tcmp.Ordered](vSlice[T]) T

SliceMax returns the maximal value in v. It panics if v is empty. Forfloating point T, SliceMax propagates NaNs (any NaN value in v forces theoutput to be NaN). See alsoslices.Max.

funcSliceMinadded inv1.88.0

func SliceMin[Tcmp.Ordered](vSlice[T]) T

SliceMin returns the minimal value in v. It panics if v is empty. Forfloating point T, SliceMin propagates NaNs (any NaN value in v forces theoutput to be NaN). See alsoslices.Min.

Types

typeByteSliceadded inv1.50.0

type ByteSlice[T ~[]byte] struct {// contains filtered or unexported fields}

ByteSlice is a read-only accessor for types that are backed by a []byte.

funcByteSliceOfadded inv1.50.0

func ByteSliceOf[T ~[]byte](x T)ByteSlice[T]

ByteSliceOf returns a ByteSlice for the provided slice.

func (ByteSlice[T])AppendToadded inv1.50.0

func (vByteSlice[T]) AppendTo(dst T) T

AppendTo appends the underlying slice values to dst.

func (ByteSlice[T])AsSliceadded inv1.50.0

func (vByteSlice[T]) AsSlice() T

AsSlice returns a copy of the underlying slice.

func (ByteSlice[T])Atadded inv1.50.0

func (vByteSlice[T]) At(iint)byte

At returns the byte at index `i` of the slice.

func (ByteSlice[T])Equaladded inv1.50.0

func (vByteSlice[T]) Equal(b T)bool

Equal reports whether the underlying slice is equal to b.

func (ByteSlice[T])EqualViewadded inv1.50.0

func (vByteSlice[T]) EqualView(bByteSlice[T])bool

EqualView reports whether the underlying slice is equal to b.

func (ByteSlice[T])IsNiladded inv1.50.0

func (vByteSlice[T]) IsNil()bool

IsNil reports whether the underlying slice is nil.

func (ByteSlice[T])Lenadded inv1.50.0

func (vByteSlice[T]) Len()int

Len returns the length of the slice.

func (ByteSlice[T])MapKeyadded inv1.60.0

func (vByteSlice[T]) MapKey()SliceMapKey[byte]

MapKey returns a unique key for a slice, based on its address and length.

func (ByteSlice[T])MarshalJSONadded inv1.50.0

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

MarshalJSON implementsjsonv1.Marshaler.

func (ByteSlice[T])MarshalJSONToadded inv1.88.0

func (vByteSlice[T]) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (ByteSlice[T])Memadded inv1.50.0

func (vByteSlice[T]) Mem()mem.RO

Mem returns a read-only view of the underlying slice.

func (ByteSlice[T])Sliceadded inv1.50.0

func (vByteSlice[T]) Slice(i, jint)ByteSlice[T]

Slice returns v[i:j]

func (ByteSlice[T])SliceFromadded inv1.50.0

func (vByteSlice[T]) SliceFrom(iint)ByteSlice[T]

SliceFrom returns v[i:].

func (ByteSlice[T])SliceToadded inv1.50.0

func (vByteSlice[T]) SliceTo(iint)ByteSlice[T]

SliceTo returns v[:i]

func (*ByteSlice[T])UnmarshalJSONadded inv1.50.0

func (v *ByteSlice[T]) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized ByteSlice.

func (*ByteSlice[T])UnmarshalJSONFromadded inv1.88.0

func (v *ByteSlice[T]) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized ByteSlice.

typeCloneradded inv1.72.0

type Cloner[Tany] interface {// Clone returns a deep-clone of the receiver.// It returns nil, when the receiver is nil.Clone() T}

Cloner is any type that has a Clone function returning a deep-clone of the receiver.

typeMapadded inv1.26.0

type Map[Kcomparable, Vany] struct {// contains filtered or unexported fields}

Map provides a read-only view of a map. It is the caller's responsibility tomake sure V is immutable.

funcMapOfadded inv1.26.0

func MapOf[Kcomparable, Vany](m map[K]V)Map[K, V]

MapOf returns a view over m. It is the caller's responsibility to make sure Vis immutable.

func (Map[K, V])Alladded inv1.76.0

func (mMap[K, V]) All()iter.Seq2[K, V]

All returns an iterator iterating over the keysand values of m.

func (Map[K, V])AsMapadded inv1.46.0

func (mMap[K, V]) AsMap() map[K]V

AsMap returns a shallow-clone of the underlying map.If V is a pointer type, it is the caller's responsibility to make surethe values are immutable.

func (Map[K, V])Containsadded inv1.70.0

func (mMap[K, V]) Contains(k K)bool

Contains reports whether k has an entry in the map.

func (Map[K, V])Getadded inv1.26.0

func (mMap[K, V]) Get(k K) V

Get returns the element with key k.

func (Map[K, V])GetOkadded inv1.26.0

func (mMap[K, V]) GetOk(k K) (V,bool)

GetOk returns the element with key k and a bool representing whether the keyis in map.

func (Map[K, V])Hasadded inv1.26.0

func (mMap[K, V]) Has(k K)bool

Has reports whether k has an entry in the map.Deprecated: use Contains instead.

func (Map[K, V])IsNiladded inv1.26.0

func (mMap[K, V]) IsNil()bool

IsNil reports whether the underlying map is nil.

func (Map[K, V])Lenadded inv1.26.0

func (mMap[K, V]) Len()int

Len returns the number of elements in the map.

func (Map[K, V])MarshalJSONadded inv1.46.0

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

MarshalJSON implementsjsonv1.Marshaler.

func (Map[K, V])MarshalJSONToadded inv1.88.0

func (mMap[K, V]) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (*Map[K, V])UnmarshalJSONadded inv1.46.0

func (m *Map[K, V]) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.It should only be called on an uninitialized Map.

func (*Map[K, V])UnmarshalJSONFromadded inv1.88.0

func (m *Map[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized Map.

typeMapFnadded inv1.26.0

type MapFn[Kcomparable, Tany, Vany] struct {// contains filtered or unexported fields}

MapFn is like Map but with a func to convert values from T to V.It is used to provide map of slices and views.

funcMapFnOfadded inv1.26.0

func MapFnOf[Kcomparable, Tany, Vany](m map[K]T, f func(T) V)MapFn[K, T, V]

MapFnOf returns a MapFn for m.

func (MapFn[K, T, V])Alladded inv1.76.0

func (mMapFn[K, T, V]) All()iter.Seq2[K, V]

All returns an iterator iterating over the keys and value views of m.

func (MapFn[K, T, V])Containsadded inv1.70.0

func (mMapFn[K, T, V]) Contains(k K)bool

Contains reports whether k has an entry in the map.

func (MapFn[K, T, V])Getadded inv1.26.0

func (mMapFn[K, T, V]) Get(k K) V

Get returns the element with key k.

func (MapFn[K, T, V])GetOkadded inv1.26.0

func (mMapFn[K, T, V]) GetOk(k K) (V,bool)

GetOk returns the element with key k and a bool representing whether the keyis in map.

func (MapFn[K, T, V])Hasadded inv1.26.0

func (mMapFn[K, T, V]) Has(k K)bool

Has reports whether k has an entry in the map.Deprecated: use Contains instead.

func (MapFn[K, T, V])IsNiladded inv1.26.0

func (mMapFn[K, T, V]) IsNil()bool

IsNil reports whether the underlying map is nil.

func (MapFn[K, T, V])Lenadded inv1.26.0

func (mMapFn[K, T, V]) Len()int

Len returns the number of elements in the map.

typeMapRangeFnadded inv1.26.0

type MapRangeFn[Kcomparable, Vany] func(k K, v V) (contbool)

MapRangeFn is the func called from a Map.Range call.Implementations should return false to stop range.

typeMapSliceadded inv1.70.0

type MapSlice[Kcomparable, Vany] struct {// contains filtered or unexported fields}

MapSlice is a view over a map whose values are slices.

funcMapSliceOfadded inv1.70.0

func MapSliceOf[Kcomparable, Vany](m map[K][]V)MapSlice[K, V]

MapSliceOf returns a MapSlice for the provided map. It is the caller'sresponsibility to make sure V is immutable.

func (MapSlice[K, V])Alladded inv1.76.0

func (mMapSlice[K, V]) All()iter.Seq2[K,Slice[V]]

All returns an iterator iterating over the keys and values of m.

func (MapSlice[K, V])AsMapadded inv1.70.0

func (mMapSlice[K, V]) AsMap() map[K][]V

AsMap returns a shallow-clone of the underlying map.

If V is a pointer type, it is the caller's responsibility to make sure thevalues are immutable. The map and slices are cloned, but the values are not.

func (MapSlice[K, V])Containsadded inv1.70.0

func (mMapSlice[K, V]) Contains(k K)bool

Contains reports whether k has an entry in the map.

func (MapSlice[K, V])Getadded inv1.70.0

func (mMapSlice[K, V]) Get(k K)Slice[V]

Get returns the element with key k.

func (MapSlice[K, V])GetOkadded inv1.70.0

func (mMapSlice[K, V]) GetOk(k K) (Slice[V],bool)

GetOk returns the element with key k and a bool representing whether the keyis in map.

func (MapSlice[K, V])IsNiladded inv1.70.0

func (mMapSlice[K, V]) IsNil()bool

IsNil reports whether the underlying map is nil.

func (MapSlice[K, V])Lenadded inv1.70.0

func (mMapSlice[K, V]) Len()int

Len returns the number of elements in the map.

func (MapSlice[K, V])MarshalJSONadded inv1.70.0

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

MarshalJSON implementsjsonv1.Marshaler.

func (MapSlice[K, V])MarshalJSONToadded inv1.88.0

func (mMapSlice[K, V]) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (*MapSlice[K, V])UnmarshalJSONadded inv1.70.0

func (m *MapSlice[K, V]) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.It should only be called on an uninitialized Map.

func (*MapSlice[K, V])UnmarshalJSONFromadded inv1.88.0

func (m *MapSlice[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It should only be called on an uninitialized MapSlice.

typeSliceadded inv1.24.0

type Slice[Tany] struct {// contains filtered or unexported fields}

Slice is a read-only accessor for a slice.

funcSliceOfadded inv1.24.0

func SliceOf[Tany](x []T)Slice[T]

SliceOf returns a Slice for the provided slice for immutable values.It is the caller's responsibility to make sure V is immutable.

func (Slice[T])Alladded inv1.74.0

func (vSlice[T]) All()iter.Seq2[int, T]

All returns an iterator over v.

func (Slice[T])AppendToadded inv1.24.0

func (vSlice[T]) AppendTo(dst []T) []T

AppendTo appends the underlying slice values to dst.

func (Slice[T])AsSliceadded inv1.24.0

func (vSlice[T]) AsSlice() []T

AsSlice returns a copy of underlying slice.

func (Slice[T])Atadded inv1.24.0

func (vSlice[T]) At(iint) T

At returns the element at index `i` of the slice.

func (Slice[T])ContainsFuncadded inv1.30.0

func (vSlice[T]) ContainsFunc(f func(T)bool)bool

ContainsFunc reports whether any element in v satisfies f(e).

As it runs in O(n) time, use with care.

func (Slice[T])IndexFuncadded inv1.30.0

func (vSlice[T]) IndexFunc(f func(T)bool)int

IndexFunc returns the first index of an element in v satisfying f(e),or -1 if none do.

As it runs in O(n) time, use with care.

func (Slice[T])IsNiladded inv1.24.0

func (vSlice[T]) IsNil()bool

IsNil reports whether the underlying slice is nil.

func (Slice[T])Lenadded inv1.24.0

func (vSlice[T]) Len()int

Len returns the length of the slice.

func (Slice[T])MapKeyadded inv1.60.0

func (vSlice[T]) MapKey()SliceMapKey[T]

MapKey returns a unique key for a slice, based on its address and length.

func (Slice[T])MarshalJSONadded inv1.24.0

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

MarshalJSON implementsjsonv1.Marshaler.

func (Slice[T])MarshalJSONToadded inv1.88.0

func (vSlice[T]) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (Slice[T])MaxFuncadded inv1.88.0

func (vSlice[T]) MaxFunc(cmp func(a, b T)int) T

MaxFunc returns the maximal value in v, using cmp to compare elements. Itpanics if v is empty. If there is more than one maximal element according tothe cmp function, MaxFunc returns the first one. See alsoslices.MaxFunc.

func (Slice[T])MinFuncadded inv1.88.0

func (vSlice[T]) MinFunc(cmp func(a, b T)int) T

MinFunc returns the minimal value in v, using cmp to compare elements. Itpanics if v is empty. If there is more than one minimal element according tothe cmp function, MinFunc returns the first one. See alsoslices.MinFunc.

func (Slice[T])Sliceadded inv1.44.0

func (vSlice[T]) Slice(i, jint)Slice[T]

Slice returns v[i:j]

func (Slice[T])SliceFromadded inv1.44.0

func (vSlice[T]) SliceFrom(iint)Slice[T]

SliceFrom returns v[i:].

func (Slice[T])SliceToadded inv1.44.0

func (vSlice[T]) SliceTo(iint)Slice[T]

SliceTo returns v[:i]

func (*Slice[T])UnmarshalJSONadded inv1.24.0

func (v *Slice[T]) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized Slice.

func (*Slice[T])UnmarshalJSONFromadded inv1.88.0

func (v *Slice[T]) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized Slice.

typeSliceMapKeyadded inv1.60.0

type SliceMapKey[Tany] struct {// contains filtered or unexported fields}

SliceMapKey represents a comparable unique key for a slice, based on itsaddress and length. It can be used to key maps by slices but should only beused when the underlying slice is immutable.

Empty and nil slices have different keys.

typeSliceViewadded inv1.26.0

type SliceView[TViewCloner[T, V], VStructView[T]] struct {// contains filtered or unexported fields}

SliceView wraps []T to provide accessors which return an immutable view V ofT. It is used to provide the equivalent of SliceOf([]V) without having toallocate []V from []T.

funcSliceOfViewsadded inv1.26.0

func SliceOfViews[TViewCloner[T, V], VStructView[T]](x []T)SliceView[T, V]

SliceOfViews returns a ViewSlice for x.

func (SliceView[T, V])Alladded inv1.76.0

func (vSliceView[T, V]) All()iter.Seq2[int, V]

All returns an iterator over v.

func (SliceView[T, V])AppendToadded inv1.26.0

func (vSliceView[T, V]) AppendTo(dst []V) []V

AppendTo appends the underlying slice values to dst.

func (SliceView[T, V])AsSliceadded inv1.26.0

func (vSliceView[T, V]) AsSlice() []V

AsSlice returns a copy of underlying slice.

func (SliceView[T, V])Atadded inv1.26.0

func (vSliceView[T, V]) At(iint) V

At returns a View of the element at index `i` of the slice.

func (SliceView[T, V])IsNiladded inv1.26.0

func (vSliceView[T, V]) IsNil()bool

IsNil reports whether the underlying slice is nil.

func (SliceView[T, V])Lenadded inv1.26.0

func (vSliceView[T, V]) Len()int

Len returns the length of the slice.

func (SliceView[T, V])MapKeyadded inv1.60.0

func (vSliceView[T, V]) MapKey()SliceMapKey[T]

MapKey returns a unique key for a slice, based on its address and length.

func (SliceView[T, V])MarshalJSONadded inv1.26.0

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

MarshalJSON implementsjsonv1.Marshaler.

func (SliceView[T, V])MarshalJSONToadded inv1.88.0

func (vSliceView[T, V]) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (SliceView[T, V])Sliceadded inv1.44.0

func (vSliceView[T, V]) Slice(i, jint)SliceView[T, V]

Slice returns v[i:j]

func (SliceView[T, V])SliceFromadded inv1.44.0

func (vSliceView[T, V]) SliceFrom(iint)SliceView[T, V]

SliceFrom returns v[i:].

func (SliceView[T, V])SliceToadded inv1.44.0

func (vSliceView[T, V]) SliceTo(iint)SliceView[T, V]

SliceTo returns v[:i]

func (*SliceView[T, V])UnmarshalJSONadded inv1.26.0

func (v *SliceView[T, V]) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized SliceView.

func (*SliceView[T, V])UnmarshalJSONFromadded inv1.88.0

func (v *SliceView[T, V]) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized SliceView.

typeStructViewadded inv1.26.0

type StructView[Tany] interface {// Valid reports whether the underlying Viewable is nil.Valid()bool// AsStruct returns a deep-copy of the underlying value.// It returns nil, if Valid() is false.AsStruct() T}

StructView represents the corresponding StructView of a Viewable. The concrete types aretypically generated by tailscale.com/cmd/viewer.

typeValuePointeradded inv1.80.0

type ValuePointer[Tany] struct {// contains filtered or unexported fields}

ValuePointer provides a read-only view of a pointer to a value type,such as a primitive type or an immutable struct. Its Value and ValueOkmethods return a stack-allocated shallow copy of the underlying value.It is the caller's responsibility to ensure that Tis free from memory aliasing/mutation concerns.

funcValuePointerOfadded inv1.80.0

func ValuePointerOf[Tany](v *T)ValuePointer[T]

ValuePointerOf returns an immutable view of a pointer to an immutable value.It is the caller's responsibility to ensure that Tis free from memory aliasing/mutation concerns.

func (ValuePointer[T])Cloneadded inv1.80.0

func (pValuePointer[T]) Clone() *T

Clone returns a shallow copy of the underlying value.

func (ValuePointer[T])Getadded inv1.80.0

func (pValuePointer[T]) Get() T

Get returns a shallow copy of the value if the underlying pointer is non-nil.Otherwise, it returns a zero value.

func (ValuePointer[T])GetOkadded inv1.80.0

func (pValuePointer[T]) GetOk() (value T, okbool)

GetOk returns a shallow copy of the underlying value and true if the underlyingpointer is non-nil. Otherwise, it returns a zero value and false.

func (ValuePointer[T])GetOradded inv1.80.0

func (pValuePointer[T]) GetOr(def T) T

GetOr returns a shallow copy of the underlying value if it is non-nil.Otherwise, it returns the provided default value.

func (ValuePointer[T])MarshalJSONadded inv1.80.0

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

MarshalJSON implementsjsonv1.Marshaler.

func (ValuePointer[T])MarshalJSONToadded inv1.88.0

func (pValuePointer[T]) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (ValuePointer[T])Stringadded inv1.80.0

func (pValuePointer[T]) String()string

String implementsfmt.Stringer.

func (*ValuePointer[T])UnmarshalJSONadded inv1.80.0

func (p *ValuePointer[T]) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized ValuePointer.

func (*ValuePointer[T])UnmarshalJSONFromadded inv1.88.0

func (p *ValuePointer[T]) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized ValuePointer.

func (ValuePointer[T])Validadded inv1.80.0

func (pValuePointer[T]) Valid()bool

Valid reports whether the underlying pointer is non-nil.

typeViewCloneradded inv1.26.0

type ViewCloner[Tany, VStructView[T]] interface {// View returns a read-only view of Viewable.// If Viewable is nil, View().Valid() reports false.View() V// Clone returns a deep-clone of Viewable.// It returns nil, when Viewable is nil.Clone() T}

ViewCloner is any type that has had View and Clone funcs generated usingtailscale.com/cmd/viewer.

Source Files

View all Source files

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