util

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(md metadata.Metadata, keys ...string) (v bool)

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

func GetDuration(md metadata.Metadata, keys ...string) (v time.Duration)

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

func GetFloat(md metadata.Metadata, keys ...string) (v float64)

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

func GetInt(md metadata.Metadata, keys ...string) (v int)

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

func GetString(md metadata.Metadata, keys ...string) (v string)

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

func GetStringMap(md metadata.Metadata, keys ...string) (m map[string]any)

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

func GetStringMapString(md metadata.Metadata, keys ...string) (m map[string]string)

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

func GetStrings(md metadata.Metadata, keys ...string) (ss []string)

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.

func IsExists

func IsExists(md metadata.Metadata, keys ...string) bool

IsExists reports whether at least one of the given keys is present in md. Returns false if md is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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