views

package
v1.26.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: BSD-3-Clause Imports: 4 Imported by: 45

Documentation

Overview

Package views provides read-only accessors for commonly used value types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPPrefixSlice

type IPPrefixSlice struct {
	// contains filtered or unexported fields
}

IPPrefixSlice is a read-only accessor for a slice of netaddr.IPPrefix.

func IPPrefixSliceOf

func IPPrefixSliceOf(x []netaddr.IPPrefix) IPPrefixSlice

IPPrefixSliceOf returns a IPPrefixSlice for the provided slice.

func (IPPrefixSlice) AppendTo

func (v IPPrefixSlice) AppendTo(dst []netaddr.IPPrefix) []netaddr.IPPrefix

AppendTo appends the underlying slice values to dst.

func (IPPrefixSlice) AsSlice

func (v IPPrefixSlice) AsSlice() []netaddr.IPPrefix

AsSlice returns a copy of underlying slice.

func (IPPrefixSlice) At

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

func (IPPrefixSlice) ContainsExitRoutes added in v1.24.0

func (v IPPrefixSlice) ContainsExitRoutes() bool

ContainsExitRoutes reports whether v contains ExitNode Routes.

func (IPPrefixSlice) ContainsFunc

func (v IPPrefixSlice) ContainsFunc(f func(netaddr.IPPrefix) bool) bool

PrefixesContainsFunc reports whether f is true for any IPPrefix in the slice.

func (IPPrefixSlice) ContainsIP

func (v IPPrefixSlice) ContainsIP(ip netaddr.IP) bool

PrefixesContainsIP reports whether any IPPrefix contains IP.

func (IPPrefixSlice) IsNil

func (v IPPrefixSlice) IsNil() bool

IsNil reports whether the underlying slice is nil.

func (IPPrefixSlice) Len

func (v IPPrefixSlice) Len() int

Len returns the length of the slice.

func (IPPrefixSlice) MarshalJSON

func (v IPPrefixSlice) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*IPPrefixSlice) UnmarshalJSON

func (v *IPPrefixSlice) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (IPPrefixSlice) Unwrap added in v1.24.0

func (v IPPrefixSlice) Unwrap() Slice[netaddr.IPPrefix]

Unwrap returns the underlying Slice[netaddr.IPPrefix].

type Map added in v1.26.0

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

Map is a view over a map whose values are immutable.

func MapOf added in v1.26.0

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

MapOf returns a view over m. It is the caller's responsibility to make sure K and V is immutable, if this is being used to provide a read-only view over m.

func (Map[K, V]) Get added in v1.26.0

func (m Map[K, V]) Get(k K) V

Get returns the element with key k.

func (Map[K, V]) GetOk added in v1.26.0

func (m Map[K, V]) GetOk(k K) (V, bool)

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

func (Map[K, V]) Has added in v1.26.0

func (m Map[K, V]) Has(k K) bool

Has reports whether k has an entry in the map.

func (Map[K, V]) IsNil added in v1.26.0

func (m Map[K, V]) IsNil() bool

IsNil reports whether the underlying map is nil.

func (Map[K, V]) Len added in v1.26.0

func (m Map[K, V]) Len() int

Len returns the number of elements in the map.

func (Map[K, V]) Range added in v1.26.0

func (m Map[K, V]) Range(f MapRangeFn[K, V])

Range calls f for every k,v pair in the underlying map. It stops iteration immediately if f returns false.

type MapFn added in v1.26.0

type MapFn[K comparable, T any, V any] 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.

func MapFnOf added in v1.26.0

func MapFnOf[K comparable, T any, V any](m map[K]T, f func(T) V) MapFn[K, T, V]

MapFnOf returns a MapFn for m.

func (MapFn[K, T, V]) Get added in v1.26.0

func (m MapFn[K, T, V]) Get(k K) V

Get returns the element with key k.

func (MapFn[K, T, V]) GetOk added in v1.26.0

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

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

func (MapFn[K, T, V]) Has added in v1.26.0

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

Has reports whether k has an entry in the map.

func (MapFn[K, T, V]) IsNil added in v1.26.0

func (m MapFn[K, T, V]) IsNil() bool

IsNil reports whether the underlying map is nil.

func (MapFn[K, T, V]) Len added in v1.26.0

func (m MapFn[K, T, V]) Len() int

Len returns the number of elements in the map.

func (MapFn[K, T, V]) Range added in v1.26.0

func (m MapFn[K, T, V]) Range(f MapRangeFn[K, V])

Range calls f for every k,v pair in the underlying map. It stops iteration immediately if f returns false.

type MapRangeFn added in v1.26.0

type MapRangeFn[K comparable, V any] func(k K, v V) (cont bool)

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

type Slice added in v1.24.0

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

Slice is a read-only accessor for a slice.

func SliceOf added in v1.24.0

func SliceOf[T any](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]) AppendTo added in v1.24.0

func (v Slice[T]) AppendTo(dst []T) []T

AppendTo appends the underlying slice values to dst.

func (Slice[T]) AsSlice added in v1.24.0

func (v Slice[T]) AsSlice() []T

AsSlice returns a copy of underlying slice.

func (Slice[T]) At added in v1.24.0

func (v Slice[T]) At(i int) T

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

func (Slice[T]) IsNil added in v1.24.0

func (v Slice[T]) IsNil() bool

IsNil reports whether the underlying slice is nil.

func (Slice[T]) Len added in v1.24.0

func (v Slice[T]) Len() int

Len returns the length of the slice.

func (Slice[T]) MarshalJSON added in v1.24.0

func (v Slice[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Slice[T]) UnmarshalJSON added in v1.24.0

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

UnmarshalJSON implements json.Unmarshaler.

type SliceView added in v1.26.0

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

SliceView is a read-only wrapper around a struct which should only be exposed as a View.

func SliceOfViews added in v1.26.0

func SliceOfViews[T ViewCloner[T, V], V StructView[T]](x []T) SliceView[T, V]

SliceOfViews returns a ViewSlice for x.

func (SliceView[T, V]) AppendTo added in v1.26.0

func (v SliceView[T, V]) AppendTo(dst []V) []V

AppendTo appends the underlying slice values to dst.

func (SliceView[T, V]) AsSlice added in v1.26.0

func (v SliceView[T, V]) AsSlice() []V

AsSlice returns a copy of underlying slice.

func (SliceView[T, V]) At added in v1.26.0

func (v SliceView[T, V]) At(i int) V

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

func (SliceView[T, V]) IsNil added in v1.26.0

func (v SliceView[T, V]) IsNil() bool

IsNil reports whether the underlying slice is nil.

func (SliceView[T, V]) Len added in v1.26.0

func (v SliceView[T, V]) Len() int

Len returns the length of the slice.

func (SliceView[T, V]) MarshalJSON added in v1.26.0

func (v SliceView[T, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SliceView[T, V]) UnmarshalJSON added in v1.26.0

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

UnmarshalJSON implements json.Unmarshaler.

type StructView added in v1.26.0

type StructView[T any] 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 are typically generated by tailscale.com/cmd/viewer.

type ViewCloner added in v1.26.0

type ViewCloner[T any, V StructView[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 using tailscale.com/cmd/viewer.

Jump to

Keyboard shortcuts

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