Documentation ¶
Index ¶
- func AddTag(ctx context.Context, key string, value interface{}) context.Context
- func AddTags(ctx context.Context, tags *Buffer) context.Context
- func RemoveTag(ctx context.Context, key string) context.Context
- func WithTags(ctx context.Context, tags *Buffer) context.Context
- type Buffer
- func (b *Buffer) Add(key string, value interface{}) *Buffer
- func (b *Buffer) FormatToString(buf *strings.Builder)
- func (b *Buffer) Get() []Tag
- func (b *Buffer) GetTag(key string) (Tag, bool)
- func (b *Buffer) Merge(other *Buffer) *Buffer
- func (b *Buffer) Remove(key string) (*Buffer, bool)
- func (b *Buffer) String() string
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTag ¶
AddTag returns a context that has the tags in the given context plus another tag. Tags are deduplicated (see Buffer.AddTag).
func AddTags ¶
AddTags returns a context that has the tags in the given context plus another set of tags. Tags are deduplicated (see Buffer.AddTags).
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is an immutable list of Tags.
func FromContext ¶
FromContext returns the tags stored in the context (by WithTags, AddTag, or AddTags).
func SingleTagBuffer ¶
SingleTagBuffer returns a Buffer with a single tag.
func (*Buffer) Add ¶
Add returns a new buffer with one more tag. If the tag has the same key as an earlier tag, that tag is overwritten. The receiver can be nil.
func (*Buffer) FormatToString ¶
FormatToString emits the k/v pairs to a strings.Builder.
- the k/v pairs are separated by commas (& no spaces).
- if there is no value, only the key is printed.
- if there is a value, and the key is just 1 character long, the key and the value are concatenated. This supports e.g. printing k="n", v=123 as "n123".
- otherwise, it prints "k=v".
func (*Buffer) GetTag ¶
GetTag returns the tag corresponding to the given key. If the tag doesn't exist, the bool return value will be false.
func (*Buffer) Merge ¶
Merge returns a new buffer which contains tags from the receiver, followed by the tags from <other>.
If both buffers have the same tag, the tag will appear only one time, with the value it has in <other>. It can appear either in the place of the tag in <b> or the tag in <other> (depending on which is deemed more efficient).
The method can return <b> or <other> if the result is identical with one of them.
The receiver can be nil.