attribute
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
Documentation¶
Overview¶
Package attribute provides key and value attributes.
Index¶
- func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue)
- func NewSetWithSortableFiltered(kvs []KeyValue, _ *Sortable, filter Filter) (Set, []KeyValue)deprecated
- type Distinct
- type Encoder
- type EncoderID
- type Filter
- type Iterator
- type Key
- func (k Key) Bool(v bool) KeyValue
- func (k Key) BoolSlice(v []bool) KeyValue
- func (k Key) Defined() bool
- func (k Key) Float64(v float64) KeyValue
- func (k Key) Float64Slice(v []float64) KeyValue
- func (k Key) Int(v int) KeyValue
- func (k Key) Int64(v int64) KeyValue
- func (k Key) Int64Slice(v []int64) KeyValue
- func (k Key) IntSlice(v []int) KeyValue
- func (k Key) String(v string) KeyValue
- func (k Key) StringSlice(v []string) KeyValue
- type KeyValue
- func Bool(k string, v bool) KeyValue
- func BoolSlice(k string, v []bool) KeyValue
- func Float64(k string, v float64) KeyValue
- func Float64Slice(k string, v []float64) KeyValue
- func Int(k string, v int) KeyValue
- func Int64(k string, v int64) KeyValue
- func Int64Slice(k string, v []int64) KeyValue
- func IntSlice(k string, v []int) KeyValue
- func String(k, v string) KeyValue
- func StringSlice(k string, v []string) KeyValue
- func Stringer(k string, v fmt.Stringer) KeyValue
- type MergeIterator
- type Set
- func (l *Set) Encoded(encoder Encoder) string
- func (l *Set) Equals(o *Set) bool
- func (l *Set) Equivalent() Distinct
- func (l *Set) Filter(re Filter) (Set, []KeyValue)
- func (l *Set) Get(idx int) (KeyValue, bool)
- func (l *Set) HasValue(k Key) bool
- func (l *Set) Iter() Iterator
- func (l *Set) Len() int
- func (l *Set) MarshalJSON() ([]byte, error)
- func (l Set) MarshalLog() any
- func (l *Set) ToSlice() []KeyValue
- func (l *Set) Value(k Key) (Value, bool)
- type Sortabledeprecated
- type Type
- type Value
- func BoolSliceValue(v []bool) Value
- func BoolValue(v bool) Value
- func Float64SliceValue(v []float64) Value
- func Float64Value(v float64) Value
- func Int64SliceValue(v []int64) Value
- func Int64Value(v int64) Value
- func IntSliceValue(v []int) Value
- func IntValue(v int) Value
- func StringSliceValue(v []string) Value
- func StringValue(v string) Value
- func (v Value) AsBool() bool
- func (v Value) AsBoolSlice() []bool
- func (v Value) AsFloat64() float64
- func (v Value) AsFloat64Slice() []float64
- func (v Value) AsInt64() int64
- func (v Value) AsInt64Slice() []int64
- func (v Value) AsInterface() any
- func (v Value) AsString() string
- func (v Value) AsStringSlice() []string
- func (v Value) Emit() string
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) Type() Type
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcNewSetWithFiltered¶
NewSetWithFiltered returns a new Set. See the documentation forNewSetWithSortableFiltered for more details.
This call includes a Filter to include/exclude attribute keys from thereturn value. Excluded keys are returned as a slice of attribute values.
funcNewSetWithSortableFiltereddeprecated
NewSetWithSortableFiltered returns a new Set.
Duplicate keys are eliminated by taking the last value. Thisre-orders the input slice so that unique last-values are contiguousat the end of the slice.
This ensures the following:
- Last-value-wins semantics- Caller sees the reordering, but doesn't lose values- Repeated call preserve last-value wins.
Note that methods are defined on Set, although this returns Set. Callerscan avoid memory allocations by:
- allocating a Sortable for use as a temporary in this method- allocating a Set for storing the return value of this constructor.
The result maintains a cache of encoded attributes, by attribute.EncoderID.This value should not be copied after its first use.
The second []KeyValue return value is a list of attributes that wereexcluded by the Filter (if non-nil).
Deprecated: UseNewSetWithFiltered instead.
Types¶
typeDistinct¶
type Distinct struct {// contains filtered or unexported fields}Distinct is an identifier of a Set which is very likely to be unique.
Distinct should be used as a map key instead of a Set for to provide betterperformance for map operations.
typeEncoder¶
type Encoder interface {// Encode returns the serialized encoding of the attribute set using// its Iterator. This result may be cached by an attribute.Set.Encode(iteratorIterator)string// ID returns a value that is unique for each class of attribute// encoder. Attribute encoders allocate these using `NewEncoderID`.ID()EncoderID}Encoder is a mechanism for serializing an attribute set into a specificstring representation that supports caching, to avoid repeatedserialization. An example could be an exporter encoding the attributeset into a wire representation.
funcDefaultEncoder¶
func DefaultEncoder()Encoder
DefaultEncoder returns an attribute encoder that encodes attributes in sucha way that each escaped attribute's key is followed by an equal sign andthen by an escaped attribute's value. All key-value pairs are separated bya comma.
Escaping is done by prepending a backslash before either a backslash, equalsign or a comma.
typeEncoderID¶
type EncoderID struct {// contains filtered or unexported fields}EncoderID is used to identify distinct Encoderimplementations, for caching encoded results.
funcNewEncoderID¶
func NewEncoderID()EncoderID
NewEncoderID returns a unique attribute encoder ID. It should be calledonce per each type of attribute encoder. Preferably in init() or in vardefinition.
func (EncoderID)Valid¶
Valid reports whether this encoder ID was allocated byNewEncoderID. Invalid encoder IDs will not be cached.
typeFilter¶
Filter supports removing certain attributes from attribute sets. Whenthe filter returns true, the attribute will be kept in the filteredattribute set. When the filter returns false, the attribute is excludedfrom the filtered attribute set, and the attribute instead appears inthe removed list of excluded attributes.
funcNewAllowKeysFilter¶added inv1.17.0
NewAllowKeysFilter returns a Filter that only allows attributes with one ofthe provided keys.
If keys is empty a deny-all filter is returned.
funcNewDenyKeysFilter¶added inv1.17.0
NewDenyKeysFilter returns a Filter that only allows attributesthat do not have one of the provided keys.
If keys is empty an allow-all filter is returned.
typeIterator¶
type Iterator struct {// contains filtered or unexported fields}Iterator allows iterating over the set of attributes in order, sorted bykey.
func (*Iterator)Attribute¶
Attribute returns the current KeyValue of the Iterator. It must be calledonly after Next returns true.
func (*Iterator)IndexedAttribute¶added inv1.7.0
IndexedAttribute returns current index and attribute. Must be called onlyafter Next returns true.
func (*Iterator)IndexedLabeldeprecated
typeKey¶
type Keystring
Key represents the key part in key-value pairs. It's a string. Theallowed character set in the key depends on the use of the key.
func (Key)Bool¶
Bool creates a KeyValue instance with a BOOL Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- Bool(name, value).
func (Key)BoolSlice¶added inv1.0.0
BoolSlice creates a KeyValue instance with a BOOLSLICE Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- BoolSlice(name, value).
func (Key)Float64¶
Float64 creates a KeyValue instance with a FLOAT64 Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- Float64(name, value).
func (Key)Float64Slice¶added inv1.0.0
Float64Slice creates a KeyValue instance with a FLOAT64SLICE Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- Float64(name, value).
func (Key)Int¶
Int creates a KeyValue instance with an INT64 Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- Int(name, value).
func (Key)Int64¶
Int64 creates a KeyValue instance with an INT64 Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- Int64(name, value).
func (Key)Int64Slice¶added inv1.0.0
Int64Slice creates a KeyValue instance with an INT64SLICE Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- Int64Slice(name, value).
func (Key)IntSlice¶added inv1.0.0
IntSlice creates a KeyValue instance with an INT64SLICE Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- IntSlice(name, value).
func (Key)String¶
String creates a KeyValue instance with a STRING Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- String(name, value).
func (Key)StringSlice¶added inv1.0.0
StringSlice creates a KeyValue instance with a STRINGSLICE Value.
If creating both a key and value at the same time, use the providedconvenience function instead -- StringSlice(name, value).
typeKeyValue¶
KeyValue holds a key and value pair.
funcFloat64Slice¶added inv1.0.0
Float64Slice creates a KeyValue with a FLOAT64SLICE Value type.
funcInt64Slice¶added inv1.0.0
Int64Slice creates a KeyValue with an INT64SLICE Value type.
funcStringSlice¶added inv1.0.0
StringSlice creates a KeyValue with a STRINGSLICE Value type.
typeMergeIterator¶
type MergeIterator struct {// contains filtered or unexported fields}MergeIterator supports iterating over two sets of attributes whileeliminating duplicate values from the combined set. The first iteratorvalue takes precedence.
funcNewMergeIterator¶
func NewMergeIterator(s1, s2 *Set)MergeIterator
NewMergeIterator returns a MergeIterator for merging two attribute sets.Duplicates are resolved by taking the value from the first set.
func (*MergeIterator)Attribute¶added inv1.7.0
func (m *MergeIterator) Attribute()KeyValue
Attribute returns the current value after Next() returns true.
func (*MergeIterator)Labeldeprecated
func (m *MergeIterator) Label()KeyValue
Label returns the current value after Next() returns true.
Deprecated: Use Attribute instead.
func (*MergeIterator)Next¶
func (m *MergeIterator) Next()bool
Next moves the iterator to the next position.Next reports whether there is another attribute available.
typeSet¶
type Set struct {// contains filtered or unexported fields}Set is the representation for a distinct attribute set. It manages animmutable set of attributes, with an internal cache for storingattribute encodings.
This type will remain comparable for backwards compatibility. Theequivalence of Sets across versions is not guaranteed to be stable.Prior versions may find two Sets to be equal or not when compareddirectly (i.e. ==), but subsequent versions may not. Users should usethe Equals method to ensure stable equivalence checking.
Users should also use the Distinct returned from Equivalent as a map keyinstead of a Set directly. Set has relatively poor performance when usedas a map key compared to Distinct.
funcEmptySet¶
func EmptySet() *Set
EmptySet returns a reference to a Set with no elements.
This is a convenience provided for optimized calling utility.
funcNewSet¶
NewSet returns a new Set. See the documentation forNewSetWithSortableFiltered for more details.
Except for empty sets, this method adds an additional allocation comparedwith calls that include a Sortable.
funcNewSetWithSortabledeprecated
func (*Set)Equivalent¶
Equivalent returns a value that may be used as a map key. Equal Distinctvalues are very likely to be equivalent attribute Sets. Distinct value of anyattribute set with the same elements as this, where sets are made unique bychoosing the last value in the input for any given key.
func (*Set)Filter¶
Filter returns a filtered copy of this Set. See the documentation forNewSetWithSortableFiltered for more details.
func (*Set)MarshalJSON¶
MarshalJSON returns the JSON encoding of the Set.
func (Set)MarshalLog¶added inv1.4.0
MarshalLog is the marshaling function used by the logging system to represent this Set.
typeType¶
type Typeint// nolint: revive // redefines builtin Type.
Type describes the type of the data Value holds.
const (// INVALID is used for a Value with no value set.INVALIDType =iota// BOOL is a boolean Type Value.BOOL// INT64 is a 64-bit signed integral Type Value.INT64// FLOAT64 is a 64-bit floating point Type Value.FLOAT64// STRING is a string Type Value.STRING// BOOLSLICE is a slice of booleans Type Value.BOOLSLICE// INT64SLICE is a slice of 64-bit signed integral numbers Type Value.INT64SLICE// FLOAT64SLICE is a slice of 64-bit floating point numbers Type Value.FLOAT64SLICE// STRINGSLICE is a slice of strings Type Value.STRINGSLICE)
typeValue¶
type Value struct {// contains filtered or unexported fields}Value represents the value part in key-value pairs.
funcBoolSliceValue¶added inv1.0.0
BoolSliceValue creates a BOOLSLICE Value.
funcFloat64SliceValue¶added inv1.0.0
Float64SliceValue creates a FLOAT64SLICE Value.
funcInt64SliceValue¶added inv1.0.0
Int64SliceValue creates an INT64SLICE Value.
funcIntSliceValue¶added inv1.0.0
IntSliceValue creates an INTSLICE Value.
funcStringSliceValue¶added inv1.0.0
StringSliceValue creates a STRINGSLICE Value.
func (Value)AsBoolSlice¶added inv1.0.0
AsBoolSlice returns the []bool value. Make sure that the Value's type isBOOLSLICE.
func (Value)AsFloat64¶
AsFloat64 returns the float64 value. Make sure that the Value'stype is FLOAT64.
func (Value)AsFloat64Slice¶added inv1.0.0
AsFloat64Slice returns the []float64 value. Make sure that the Value's type isFLOAT64SLICE.
func (Value)AsInt64Slice¶added inv1.0.0
AsInt64Slice returns the []int64 value. Make sure that the Value's type isINT64SLICE.
func (Value)AsStringSlice¶added inv1.0.0
AsStringSlice returns the []string value. Make sure that the Value's type isSTRINGSLICE.
func (Value)MarshalJSON¶
MarshalJSON returns the JSON encoding of the Value.
Source Files¶
Directories¶
| Path | Synopsis |
|---|---|
Package attribute provide several helper functions for some commonly used logic of processing attributes. | Package attribute provide several helper functions for some commonly used logic of processing attributes. |
xxhash Package xxhash provides a wrapper around the xxhash library for attribute hashing. | Package xxhash provides a wrapper around the xxhash library for attribute hashing. |