Documentation ¶
Overview ¶
Package attribute is focused on enabling efficient handling and tracking of attribute usage within Mixer.
Index ¶
- func CheckType(value interface{}) bool
- func Equal(this, that interface{}) bool
- func GetProtoForTesting(v map[string]interface{}) *mixerpb.CompressedAttributes
- func GlobalList() []string
- type Bag
- type List
- type MutableBag
- func (mb *MutableBag) Contains(key string) bool
- func (mb *MutableBag) Delete(name string)
- func (mb *MutableBag) Done()
- func (mb *MutableBag) Get(name string) (interface{}, bool)
- func (mb *MutableBag) Merge(bag *MutableBag)
- func (mb *MutableBag) Names() []string
- func (mb *MutableBag) Reset()
- func (mb *MutableBag) Set(name string, value interface{})
- func (mb *MutableBag) String() string
- func (mb *MutableBag) ToProto(output *mixerpb.CompressedAttributes, globalDict map[string]int32, ...)
- func (mb *MutableBag) UpdateBagFromProto(attrs *mixerpb.CompressedAttributes, globalWordList []string) error
- type ProtoBag
- func (pb *ProtoBag) ClearReferencedAttributes()
- func (pb *ProtoBag) Contains(key string) bool
- func (pb *ProtoBag) Done()
- func (pb *ProtoBag) Get(name string) (interface{}, bool)
- func (pb *ProtoBag) GetReferencedAttributes(globalDict map[string]int32, globalWordCount int) *mixerpb.ReferencedAttributes
- func (pb *ProtoBag) Names() []string
- func (pb *ProtoBag) RestoreReferencedAttributes(snap ReferencedAttributeSnapshot)
- func (pb *ProtoBag) SnapshotReferencedAttributes() ReferencedAttributeSnapshot
- func (pb *ProtoBag) String() string
- type ReferencedAttributeSnapshot
- type StringMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckType ¶
func CheckType(value interface{}) bool
CheckType validates that an attribute value has a supported type.
func GetProtoForTesting ¶
func GetProtoForTesting(v map[string]interface{}) *mixerpb.CompressedAttributes
GetProtoForTesting returns a CompressedAttributes struct based on the specified map Use this function only for testing purposes.
func GlobalList ¶
func GlobalList() []string
Types ¶
type Bag ¶
type Bag interface { fmt.Stringer // Get returns an attribute value. Get(name string) (value interface{}, found bool) // Names returns the names of all the attributes known to this bag. Names() []string // Contains returns true if this bag contains the specified key. Contains(key string) bool // Done indicates the bag can be reclaimed. Done() }
Bag is a generic mechanism to access a set of attributes.
The type of an attribute value is guaranteed to be one of the following: - int64 - string - float64 - bool - time.Time - time.Duration - []byte (backed by a byte array) - attribute.StringMap (backed by a map[string]string)
Attribute value types are physical representation of the semantic Mixer types. For example, IP addresses are represented as []byte.
The following types are not fully implemented at the surface level: - *attribute.List (note the pointer, backed by []interface{})
type List ¶
type List struct {
// contains filtered or unexported fields
}
List wraps a list of values and optionally reference counts it
func NewListForTesting ¶
NewListForTesting should only be used for testing.
type MutableBag ¶
type MutableBag struct {
// contains filtered or unexported fields
}
MutableBag is a generic mechanism to read and write a set of attributes.
Bags can be chained together in a parent/child relationship. A child bag represents a delta over a parent. By default a child looks identical to the parent. But as mutations occur to the child, the two start to diverge. Resetting a child makes it look identical to its parent again.
func GetBagFromProto ¶
func GetBagFromProto(attrs *mixerpb.CompressedAttributes, globalWordList []string) (*MutableBag, error)
GetBagFromProto returns an initialized bag from an Attribute proto.
func GetMutableBag ¶
func GetMutableBag(parent Bag) *MutableBag
GetMutableBag returns an initialized bag.
Bags can be chained in a parent/child relationship. You can pass nil if the bag has no parent.
When you are done using the mutable bag, call the Done method to recycle it.
func GetMutableBagForTesting ¶
func GetMutableBagForTesting(values map[string]interface{}) *MutableBag
GetMutableBagForTesting returns a Mutable bag based on the specified map Use this function only for testing purposes.
func (*MutableBag) Contains ¶
func (mb *MutableBag) Contains(key string) bool
Contains returns true if the key is present in the bag.
func (*MutableBag) Delete ¶
func (mb *MutableBag) Delete(name string)
Delete removes a named item from the local state. The item may still be present higher in the hierarchy
func (*MutableBag) Get ¶
func (mb *MutableBag) Get(name string) (interface{}, bool)
Get returns an attribute value.
func (*MutableBag) Merge ¶
func (mb *MutableBag) Merge(bag *MutableBag)
Merge combines an array of bags into the current bag. If the current bag already defines a particular attribute, it keeps its value and is not overwritten.
Note that this does a 'shallow' merge. Only the value defined explicitly in the mutable bags themselves, and not in any of their parents, are considered.
func (*MutableBag) Names ¶
func (mb *MutableBag) Names() []string
Names returns the names of all the attributes known to this bag.
func (*MutableBag) Set ¶
func (mb *MutableBag) Set(name string, value interface{})
Set creates an override for a named attribute.
func (*MutableBag) String ¶
func (mb *MutableBag) String() string
String prints out the attributes from the parent bag, then walks through the local changes and prints them as well.
func (*MutableBag) ToProto ¶
func (mb *MutableBag) ToProto(output *mixerpb.CompressedAttributes, globalDict map[string]int32, globalWordCount int)
ToProto fills-in an Attributes proto based on the content of the bag.
func (*MutableBag) UpdateBagFromProto ¶
func (mb *MutableBag) UpdateBagFromProto(attrs *mixerpb.CompressedAttributes, globalWordList []string) error
UpdateBagFromProto refreshes the bag based on the content of the attribute proto.
Note that in the case of semantic errors in the supplied proto which leads to an error return, it's likely that the bag will have been partially updated.
type ProtoBag ¶
type ProtoBag struct {
// contains filtered or unexported fields
}
ProtoBag implements the Bag interface on top of an Attributes proto.
func NewProtoBag ¶
func NewProtoBag(proto *mixerpb.CompressedAttributes, globalDict map[string]int32, globalWordList []string) *ProtoBag
NewProtoBag creates a new proto-based attribute bag.
func (*ProtoBag) ClearReferencedAttributes ¶
func (pb *ProtoBag) ClearReferencedAttributes()
ClearReferencedAttributes clears the list of referenced attributes being tracked by this bag
func (*ProtoBag) GetReferencedAttributes ¶
func (pb *ProtoBag) GetReferencedAttributes(globalDict map[string]int32, globalWordCount int) *mixerpb.ReferencedAttributes
GetReferencedAttributes returns the set of attributes that have been referenced through this bag.
func (*ProtoBag) RestoreReferencedAttributes ¶
func (pb *ProtoBag) RestoreReferencedAttributes(snap ReferencedAttributeSnapshot)
RestoreReferencedAttributes sets the list of referenced attributes being tracked by this bag
func (*ProtoBag) SnapshotReferencedAttributes ¶
func (pb *ProtoBag) SnapshotReferencedAttributes() ReferencedAttributeSnapshot
SnapshotReferencedAttributes grabs a snapshot of the currently referenced attributes
type ReferencedAttributeSnapshot ¶
type ReferencedAttributeSnapshot struct {
// contains filtered or unexported fields
}
ReferencedAttributeSnapshot keeps track of the attribute reference state for a mutable bag. You can snapshot the referenced attributes with SnapshotReferencedAttributes and later reinstall them with RestoreReferencedAttributes. Note that a snapshot can only be used once, the RestoreReferencedAttributes call is destructive.
type StringMap ¶
type StringMap struct {
// contains filtered or unexported fields
}
StringMap wraps a map[string]string and optionally reference counts it
func NewStringMap ¶
NewStringMap instantiates a new string map.
func WrapStringMap ¶
WrapStringMap wraps a string map value without reference tracking.