tags

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tags provides a concurrency-safe string tag map for AWS resource annotations.

Tags is built on safemap.Map and therefore inherits full Prometheus instrumentation via [lockmetrics.RWMutex].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapFromKV added in v1.1.2

func MapFromKV(items []KV) map[string]string

MapFromKV converts a slice of KV to a map.

Types

type KV

type KV struct {
	Key   string `json:"Key"   xml:"Key"`
	Value string `json:"Value" xml:"Value"`
}

KV is a key-value tag pair for use in JSON and XML serialization. It is the canonical representation of a single AWS resource tag and is used by handler types across service packages.

func MapToKV added in v1.1.2

func MapToKV(m map[string]string) []KV

MapToKV converts a map to a sorted slice of KV.

type Tags

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

Tags is a concurrency-safe collection of string key-value tag pairs.

The zero value is not usable; always create via New or FromMap.

func FromMap

func FromMap(name string, src map[string]string) *Tags

FromMap creates a Tags collection pre-populated from src.

func New

func New(name string) *Tags

New creates a new Tags collection. The name appears as the "lock" label in Prometheus metrics (e.g. "sqs.queue.my-queue.tags").

func (*Tags) Clone

func (t *Tags) Clone() map[string]string

Clone returns a plain map[string]string copy of the tags.

func (*Tags) Close

func (t *Tags) Close()

Close releases resources associated with this Tags collection, removing the underlying lockmetrics.RWMutex from the global Prometheus registry. It should be called when the Tags instance is no longer needed to prevent unbounded growth of the global collector. After Close is called, the Tags must not be used.

func (*Tags) Delete

func (t *Tags) Delete(key string)

Delete removes the tag with the given key.

func (*Tags) DeleteKeys

func (t *Tags) DeleteKeys(keys []string)

DeleteKeys removes all tags whose key appears in keys.

func (*Tags) Get

func (t *Tags) Get(key string) (string, bool)

Get returns the value for key and whether it was found.

func (*Tags) HasTag

func (t *Tags) HasTag(key string) bool

HasTag reports whether key exists.

func (*Tags) Len

func (t *Tags) Len() int

Len returns the number of tags.

func (*Tags) MarshalJSON

func (t *Tags) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. Tags serialises as a plain JSON object (e.g. {"env":"prod","team":"platform"}).

func (*Tags) MatchesFilter

func (t *Tags) MatchesFilter(filter map[string]string) bool

MatchesFilter reports whether t contains all key-value pairs in filter. An empty filter always returns true.

func (*Tags) Merge

func (t *Tags) Merge(src map[string]string)

Merge adds all entries from src into t, overwriting existing keys.

func (*Tags) Range

func (t *Tags) Range(f func(key, value string) bool)

Range calls f sequentially for each tag in unspecified order. The underlying map is read-locked for the entire iteration; f must not call methods on the same Tags to avoid deadlocks. Iteration stops early if f returns false.

func (*Tags) Set

func (t *Tags) Set(key, value string)

Set adds or updates a tag.

func (*Tags) UnmarshalJSON

func (t *Tags) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. Tags deserialises from a plain JSON object (e.g. {"env":"prod","team":"platform"}). An empty or null JSON value produces an empty Tags with the zero-value name; callers that care about the Prometheus lock name should prefer FromMap for static data. Any keys previously present in t that are absent from the JSON payload are removed, so the result matches the JSON payload exactly.

Jump to

Keyboard shortcuts

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