Documentation
¶
Overview ¶
Package utils provides shared helpers for flag registration and value parsing.
Index ¶
- func DurationFromSeconds(seconds float64) time.Duration
- func EnvBool(key string) bool
- func EnvDuration(key string) time.Duration
- func EnvInt(key string) int
- func EnvString(key string) string
- func FilterEmptyStrings(values []string) []string
- func IsPureNumeric(str string) bool
- func MarkFlagDeprecated(flagSet *pflag.FlagSet, name, hint string)
- func SplitCommaOnly(value string) []string
- func SplitCommaOrSpace(value string) []string
- func SplitNotificationValues(value string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DurationFromSeconds ¶
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 ¶
EnvBool fetches a boolean from an environment variable via Viper.
Parameters:
- key: Environment variable key.
Returns:
- bool: Value or false if unset.
func EnvDuration ¶
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 ¶
EnvInt fetches an integer from an environment variable via Viper.
Parameters:
- key: Environment variable key.
Returns:
- int: Value or 0 if unset.
func EnvString ¶
EnvString fetches a string from an environment variable via Viper.
Parameters:
- key: Environment variable key.
Returns:
- string: Value or empty if unset.
func FilterEmptyStrings ¶
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 ¶
IsPureNumeric reports whether str is a bare number (integer or float, possibly signed) with no duration unit characters.
func MarkFlagDeprecated ¶
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 ¶
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 ¶
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 ¶
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.