Documentation
¶
Overview ¶
Package util provides typed accessor functions for reading values from a metadata.Metadata store. Each getter accepts one or more fallback keys and returns the first match. All functions are nil-safe on the metadata argument.
Index ¶
- func GetBool(md metadata.Metadata, keys ...string) (v bool)
- func GetDuration(md metadata.Metadata, keys ...string) (v time.Duration)
- func GetFloat(md metadata.Metadata, keys ...string) (v float64)
- func GetInt(md metadata.Metadata, keys ...string) (v int)
- func GetString(md metadata.Metadata, keys ...string) (v string)
- func GetStringMap(md metadata.Metadata, keys ...string) (m map[string]any)
- func GetStringMapString(md metadata.Metadata, keys ...string) (m map[string]string)
- func GetStrings(md metadata.Metadata, keys ...string) (ss []string)
- func IsExists(md metadata.Metadata, keys ...string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBool ¶
GetBool returns the bool value for the first matching key. String values are parsed with strconv.ParseBool, and non-zero integers are treated as true. Returns false if md is nil or no key matches.
func GetDuration ¶
GetDuration returns the time.Duration value for the first matching key. String values are parsed with time.ParseDuration; if that fails they are retried as integer seconds via strconv.Atoi. Integer values are treated as seconds. Returns 0 if md is nil or no key matches.
func GetFloat ¶
GetFloat returns the float64 value for the first matching key. String values are parsed with strconv.ParseFloat, float32 values are promoted, and int values are converted. Returns 0 if md is nil or no key matches.
func GetInt ¶
GetInt returns the int value for the first matching key. String values are parsed with strconv.Atoi, and true/false booleans are treated as 1/0. Returns 0 if md is nil or no key matches.
func GetString ¶
GetString returns the string value for the first matching key. Non-string values (int, int64, uint, uint64, bool, float32, float64) are formatted via strconv. Returns "" if md is nil or no key matches.
func GetStringMap ¶
GetStringMap returns the map[string]any value for the first matching key. map[any]any values are converted by formatting keys with %v. Returns nil if md is nil or no key matches.
func GetStringMapString ¶
GetStringMapString returns the map[string]string value for the first matching key. Both map[string]any and map[any]any values are converted by formatting values with %v. Returns nil if md is nil or no key matches.
func GetStrings ¶
GetStrings returns the []string value for the first matching key. []any slices are converted element-by-element, skipping non-string values. Returns nil if md is nil or no key matches.
Types ¶
This section is empty.