tag

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNamespace = ""

DefaultNamespace is the default namespace for tags

View Source
var EmptySet = Set{}

Functions

func ExpectTagsOnContext added in v0.3.0

func ExpectTagsOnContext(ctx context.Context, expectedTags ...*Tag) error

func WithComponent

func WithComponent(ctx context.Context, component string) context.Context

WithComponent returns a new context with the component chained tag added to the default namespace set.

func WithNamespaceTags

func WithNamespaceTags(ctx context.Context, namespace string, tags ...*Tag) context.Context

WithNamespaceTags returns a new context with the given added to the namespace set. The namespace set on the parent context is not modified.

func WithTags

func WithTags(ctx context.Context, tags ...*Tag) context.Context

WithTags returns a new context with the given tags added to the default namespace set.

Types

type Key

type Key string

Key represents the key part in key-value pairs. It's a string. The allowed character set in the key depends on the use of the key.

func (Key) Bool

func (k Key) Bool(b bool) *Tag

Bool creates a new tag with a boolean value.

func (Key) Float64

func (k Key) Float64(f float64) *Tag

Float64 creates a new tag with a 64-bit floating point value.

func (Key) Int64

func (k Key) Int64(i int64) *Tag

Int64 creates a new tag with a 64-bit signed integral value.

func (Key) Object

func (k Key) Object(o interface{}) *Tag

Object creates a new tag with a generic object value.

func (Key) String

func (k Key) String(s string) *Tag

String creates a new tag with a string value.

type Set

type Set []*Tag

Set represents a immutable set of

func FromContext

func FromContext(ctx context.Context) Set

FromContext returns the set of tags from the context for the default namespace set

func FromNamespaceContext

func FromNamespaceContext(ctx context.Context, namespace string) Set

FromNamespaceContext returns the set of tags for the given namespace from the context.

func (Set) WithTags

func (s Set) WithTags(tags ...*Tag) Set

WithTags returns a new set with the given tags added to the set. If a tag with the same key already exists in the set, the new tag will replace the old tag.

type Tag

type Tag struct {
	Key   Key
	Value Value
	// contains filtered or unexported fields
}

A tag is a key-value pair that can be attached to a context It is used to carry metadata about a given context execution along the context chain It is primarily used for rich instrumentation of the application: logging, metrics, tracing

func BoolTag

func BoolTag(key string, value bool) *Tag

BoolTag creates a new tag with a boolean value.

func Float64Tag

func Float64Tag(key string, value float64) *Tag

Float64Tag creates a new tag with a 64-bit floating point value.

func Int64Tag

func Int64Tag(key string, value int64) *Tag

Int64Tag creates a new tag with a 64-bit signed integral value.

func ObjectTag

func ObjectTag(key string, value interface{}) *Tag

ObjectTag creates a new tag with a generic object value.

func StringTag

func StringTag(key, value string) *Tag

StringTag creates a new tag with a string value.

func (*Tag) Chained

func (t *Tag) Chained(b bool) *Tag

Chained flags the tag as chained.

func (*Tag) Copy

func (t *Tag) Copy() *Tag

Copy returns a copy of the tag.

type Type

type Type int

Type describes the type of the Value holds.

const (
	// INVALID is used for a Value with no value set.
	INVALID Type = 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
	// OBJECT is a generic object Type Value.
	OBJECT
)

type Value

type Value struct {
	Type      Type
	Interface interface{}
}

Value represents a tag value.

func BoolValue

func BoolValue(v bool) Value

BoolValue returns a Value with a boolean value set.

func Float64Value

func Float64Value(v float64) Value

Float64Value returns a Value with a 64-bit floating point value set.

func Int64Value

func Int64Value(v int64) Value

Int64Value returns a Value with a 64-bit signed integral value set.

func InvalidValue

func InvalidValue() Value

InvalidValue returns a Value with no value set.

func ObjectValue

func ObjectValue(v interface{}) Value

ObjectValue returns a Value with a generic object value set.

func StringValue

func StringValue(v string) Value

StringValue returns a Value with a string value set.

func (*Value) String added in v0.3.0

func (v *Value) String() string

Jump to

Keyboard shortcuts

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