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
- Variables
- func IsPinnedIDKey(key string) bool
- func MapFromKV(items []KV) map[string]string
- func PinnedIDFromList[T any](list []T, kv func(T) (string, string)) (string, []T)
- func PinnedIDFromMap(m map[string]string) (string, map[string]string)
- func PinnedIDFromTagSpecs(vals url.Values, resourceType string) string
- func ValidatePinnedID(id string, re *regexp.Regexp, format string) error
- type KV
- type Tags
- func (t *Tags) Clone() map[string]string
- func (t *Tags) Close()
- func (t *Tags) Delete(key string)
- func (t *Tags) DeleteKeys(keys []string)
- func (t *Tags) Get(key string) (string, bool)
- func (t *Tags) HasTag(key string) bool
- func (t *Tags) Len() int
- func (t *Tags) MarshalJSON() ([]byte, error)
- func (t *Tags) MatchesFilter(filter map[string]string) bool
- func (t *Tags) Merge(src map[string]string)
- func (t *Tags) Range(f func(key, value string) bool)
- func (t *Tags) Set(key, value string)
- func (t *Tags) UnmarshalJSON(data []byte) error
Constants ¶
const PinnedIDKey = "gopherstack:id"
PinnedIDKey is the emulator-only create-time tag that pins a generated resource ID. It is consumed on create and never stored or listed.
Variables ¶
var ErrInvalidPinnedID = errors.New("invalid " + PinnedIDKey + " tag")
ErrInvalidPinnedID is returned when a pinned ID does not match the resource type's ID format.
Functions ¶
func IsPinnedIDKey ¶
IsPinnedIDKey reports whether key is the reserved ID-pinning tag.
func PinnedIDFromList ¶
PinnedIDFromList returns the pinned ID in list and the list without the reserved entry; kv extracts the key and value of one element.
func PinnedIDFromMap ¶
PinnedIDFromMap returns the pinned ID in m and a copy of m without the reserved key. m is returned unchanged when the key is absent.
func PinnedIDFromTagSpecs ¶
PinnedIDFromTagSpecs returns the pinned ID from the EC2 query-protocol TagSpecification.N entries whose ResourceType equals resourceType.
func ValidatePinnedID ¶
ValidatePinnedID checks id against re and wraps ErrInvalidPinnedID with a message naming the expected format.
Types ¶
type KV ¶
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.
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 New ¶
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) 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) DeleteKeys ¶
DeleteKeys removes all tags whose key appears in keys.
func (*Tags) MarshalJSON ¶
MarshalJSON implements json.Marshaler. Tags serialises as a plain JSON object (e.g. {"env":"prod","team":"platform"}).
func (*Tags) MatchesFilter ¶
MatchesFilter reports whether t contains all key-value pairs in filter. An empty filter always returns true.
func (*Tags) Range ¶
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) UnmarshalJSON ¶
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.