utils

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package utils provides shared helpers for flag registration and value parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationFromSeconds

func DurationFromSeconds(seconds float64) time.Duration

DurationFromSeconds converts a floating-point second count to time.Duration.

The nanosecond product is clamped to MaxInt64/MinInt64 when it would overflow time.Duration's integer range.

Parameters:

  • seconds: Duration length in seconds (may be fractional).

Returns:

  • time.Duration: Clamped duration value.

func EnvBool

func EnvBool(key string) bool

EnvBool fetches a boolean from an environment variable via Viper.

Parameters:

  • key: Environment variable key.

Returns:

  • bool: Value or false if unset.

func EnvDuration

func EnvDuration(key string) time.Duration

EnvDuration fetches a duration from an environment variable.

Bare values without a time unit are treated as seconds.

Parameters:

  • key: Environment variable key.

Returns:

  • time.Duration: Value or 0 if unset.

func EnvInt

func EnvInt(key string) int

EnvInt fetches an integer from an environment variable via Viper.

Parameters:

  • key: Environment variable key.

Returns:

  • int: Value or 0 if unset.

func EnvString

func EnvString(key string) string

EnvString fetches a string from an environment variable via Viper.

Parameters:

  • key: Environment variable key.

Returns:

  • string: Value or empty if unset.

func FilterEmptyStrings

func FilterEmptyStrings(values []string) []string

FilterEmptyStrings removes empty or whitespace-only strings from a slice.

Parameters:

  • values: Slice of strings.

Returns:

  • []string: Filtered slice without empty or whitespace-only strings.

func IsPureNumeric

func IsPureNumeric(str string) bool

IsPureNumeric reports whether str is a bare number (integer or float, possibly signed) with no duration unit characters.

func MarkFlagDeprecated

func MarkFlagDeprecated(flagSet *pflag.FlagSet, name, hint string)

MarkFlagDeprecated marks a pflag as deprecated with a migration hint.

Parameters:

  • flagSet: Flag set containing the flag.
  • name: Flag name.
  • hint: Migration hint message.

TODO: Remove MarkFlagDeprecated and all legacy flags in the v2 release.

func SplitCommaOnly

func SplitCommaOnly(value string) []string

SplitCommaOnly splits on commas only and drops empty tokens.

Parameters:

  • value: Raw list string from env or defaults.

Returns:

  • []string: Parsed non-empty tokens.

func SplitCommaOrSpace

func SplitCommaOrSpace(value string) []string

SplitCommaOrSpace splits on commas and/or spaces and drops empty tokens.

Parameters:

  • value: Raw list string from env or defaults.

Returns:

  • []string: Parsed non-empty tokens.

func SplitNotificationValues

func SplitNotificationValues(value string) []string

SplitNotificationValues parses notification URLs separated by commas or spaces.

Comma-delimited fragments without "://" are recombined so commas inside URLs (query params, tenant IDs) are preserved.

Parameters:

  • value: A string containing one or more notification URLs.

Returns:

  • []string: Parsed notification URLs. Invalid URLs are included but logged.

Types

This section is empty.

Jump to

Keyboard shortcuts

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