Documentation
¶
Index ¶
- Variables
- func DefaultValues(rs ...interface{})
- func DeprecatedFlag(f *flag.FlagSet, name, message string, logger log.Logger)
- func FlagToEnvVar(prefix, flagName string) string
- func IgnoredFlag(f *flag.FlagSet, name, message string)
- func ParseFlagsAndArguments(f *flag.FlagSet) ([]string, error)
- func ParseFlagsAndArgumentsWithEnv(f *flag.FlagSet, prefix string) ([]string, error)
- func ParseFlagsWithoutArguments(f *flag.FlagSet) error
- func ParseFlagsWithoutArgumentsWithEnv(f *flag.FlagSet, prefix string) error
- func RegisterFlags(rs ...Registerer)
- func RegisterFlagsWithLogger(logger log.Logger, rs ...interface{})
- func SetFlagsFromEnv(f *flag.FlagSet, prefix string) error
- func SetFlagsFromEnvWithLookup(f *flag.FlagSet, prefix string, lookup func(string) (string, bool)) error
- type Bytes
- type CIDR
- type CIDRSliceCSV
- type DayValue
- type LimitsMap
- func (m LimitsMap[T]) Clone() LimitsMap[T]
- func (m LimitsMap[T]) Equal(other LimitsMap[T]) bool
- func (m LimitsMap[T]) IsInitialized() bool
- func (m LimitsMap[T]) MarshalYAML() (interface{}, error)
- func (m LimitsMap[T]) Read() map[string]T
- func (m LimitsMap[T]) Set(s string) error
- func (m LimitsMap[T]) String() string
- func (m LimitsMap[T]) UnmarshalYAML(value *yaml.Node) error
- type RegisteredFlags
- type RegisteredFlagsTracker
- type Registerer
- type RegistererWithLogger
- type Secret
- type StringSlice
- type StringSliceCSV
- type StringSliceCSVMulti
- type Time
- type URLValue
Constants ¶
This section is empty.
Variables ¶
var DeprecatedFlagsUsed = promauto.NewCounter( prometheus.CounterOpts{ Name: "deprecated_flags_inuse_total", Help: "The number of deprecated flags currently set.", })
DeprecatedFlagsUsed is the metric that counts deprecated flags set.
Functions ¶
func DefaultValues ¶
func DefaultValues(rs ...interface{})
DefaultValues initiates a set of configs (Registerers) with their defaults.
func DeprecatedFlag ¶
DeprecatedFlag logs a warning when you try to use it.
func FlagToEnvVar ¶
FlagToEnvVar converts a flag name to its corresponding environment variable name. The flag name is uppercased and all dots, dashes, and underscores in the flag name are replaced with (or kept as) underscores. The prefix is similarly upper-cased with symbol substitution. If prefix is non-empty, an _ is placed between the flag name and prefix
Note that distinct flag names can map to the same environment variable. For example, "a.b" and "a-b" both map to "A_B". Callers should avoid registering flags whose names differ only in dots, dashes, and underscores.
For example, FlagToEnvVar("myapp-name", "server.http-listen-port") returns "MYAPP_NAME_SERVER_HTTP_LISTEN_PORT".
func IgnoredFlag ¶
IgnoredFlag ignores set value, without any warning
func ParseFlagsAndArguments ¶
ParseFlagsAndArguments calls Parse() on the input flag.FlagSet and returns the parsed arguments.
func ParseFlagsAndArgumentsWithEnv ¶
ParseFlagsAndArgumentsWithEnv is like ParseFlagsAndArguments but also sets flag values from environment variables using SetFlagsFromEnv. CLI flags take precedence over environment variables, which take precedence over default values.
func ParseFlagsWithoutArguments ¶
ParseFlagsWithoutArguments calls Parse() on the input flag.FlagSet and enforces no arguments have been parsed. This utility should be called whenever we only expect CLI flags but no arguments.
func ParseFlagsWithoutArgumentsWithEnv ¶
ParseFlagsWithoutArgumentsWithEnv is like ParseFlagsWithoutArguments but also sets flag values from environment variables using SetFlagsFromEnv. CLI flags take precedence over environment variables, which take precedence over default values.
func RegisterFlags ¶
func RegisterFlags(rs ...Registerer)
RegisterFlags registers flags with the provided Registerers
func RegisterFlagsWithLogger ¶
RegisterFlagsWithLogger registers flags with the provided Registerers
func SetFlagsFromEnv ¶
SetFlagsFromEnv sets flag values from environment variables for any flags that were not explicitly set on the command line. It must be called after f.Parse() so that explicitly-set CLI flags can be detected.
The environment variable name for each flag is derived by FlagToEnvVar. CLI flags always take precedence over environment variables, and environment variables take precedence over default values.
func SetFlagsFromEnvWithLookup ¶
func SetFlagsFromEnvWithLookup(f *flag.FlagSet, prefix string, lookup func(string) (string, bool)) error
SetFlagsFromEnvWithLookup is like SetFlagsFromEnv but uses the provided lookup function instead of os.LookupEnv. This is useful for testing or for providing an alternative source of configuration values.
Types ¶
type Bytes ¶
type Bytes uint64
Bytes is a data type which supports use as a flag and yaml serialization/deserialization with units.
func (Bytes) MarshalYAML ¶
func (*Bytes) UnmarshalYAML ¶
type CIDRSliceCSV ¶
type CIDRSliceCSV []CIDR
CIDRSliceCSV is a slice of CIDRs that is parsed from a comma-separated string. It implements flag.Value and yaml Marshalers.
func (CIDRSliceCSV) MarshalYAML ¶
func (c CIDRSliceCSV) MarshalYAML() (interface{}, error)
MarshalYAML implements yaml.Marshaler.
func (*CIDRSliceCSV) UnmarshalYAML ¶
func (c *CIDRSliceCSV) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements yaml.Unmarshaler.
type DayValue ¶
DayValue is a model.Time that can be used as a flag. NB it only parses days!
func NewDayValue ¶
NewDayValue makes a new DayValue; will round t down to the nearest midnight.
func (DayValue) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*DayValue) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type LimitsMap ¶
LimitsMap is a flag.Value implementation that looks like a generic map, holding float64s, ints, or strings as values.
func NewLimitsMap ¶
func NewLimitsMapWithData ¶
func (LimitsMap[T]) Equal ¶
Equal compares two LimitsMap. This is needed to allow cmp.Equal to compare two LimitsMap.
func (LimitsMap[T]) IsInitialized ¶
IsInitialized returns true if the map is initialized.
func (LimitsMap[T]) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
type RegisteredFlags ¶
type RegisteredFlags struct {
// Prefix is the prefix used by the flag
Prefix string
// Flags are the flag definitions of each one of the flag names. Flag names don't contain the prefix here.
Flags map[string]*flag.Flag
}
RegisteredFlags contains the flags registered by some config.
func TrackRegisteredFlags ¶
func TrackRegisteredFlags(prefix string, f *flag.FlagSet, register func(prefix string, f *flag.FlagSet)) RegisteredFlags
TrackRegisteredFlags returns the flags that were registered by the register function. It only tracks the flags that have the given prefix.
type RegisteredFlagsTracker ¶
type RegisteredFlagsTracker interface {
RegisteredFlags() RegisteredFlags
}
RegisteredFlagsTracker is an interface that allows to extract RegisteredFlags.
type Registerer ¶
Registerer is a thing that can RegisterFlags
type RegistererWithLogger ¶
RegistererWithLogger is a thing that can RegisterFlags with a Logger
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
func SecretWithValue ¶
SecretWithValue returns Secret with specified value.
func (Secret) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Secret) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type StringSlice ¶
type StringSlice []string
StringSlice is a slice of strings that implements flag.Value
type StringSliceCSV ¶
type StringSliceCSV []string
StringSliceCSV is a slice of strings that is parsed from a comma-separated string It implements flag.Value and yaml Marshalers
func (StringSliceCSV) MarshalYAML ¶
func (v StringSliceCSV) MarshalYAML() (interface{}, error)
MarshalYAML implements yaml.Marshaler.
func (*StringSliceCSV) UnmarshalYAML ¶
func (v *StringSliceCSV) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements yaml.Unmarshaler.
type StringSliceCSVMulti ¶
type StringSliceCSVMulti []string
StringSliceCSVMulti is a slice of strings that supports both: - Multiple flag invocations (values are appended) - Comma-separated values (split on commas) It implements flag.Value
func (StringSliceCSVMulti) MarshalYAML ¶
func (v StringSliceCSVMulti) MarshalYAML() (interface{}, error)
MarshalYAML implements yaml.Marshaler.
func (*StringSliceCSVMulti) Set ¶
func (v *StringSliceCSVMulti) Set(s string) error
Set implements flag.Value
func (StringSliceCSVMulti) String ¶
func (v StringSliceCSVMulti) String() string
String implements flag.Value
func (*StringSliceCSVMulti) UnmarshalYAML ¶
func (v *StringSliceCSVMulti) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements yaml.Unmarshaler.
type Time ¶
Time usable as flag or in YAML config.
func (Time) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Time) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type URLValue ¶
URLValue is a url.URL that can be used as a flag.
func (URLValue) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*URLValue) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.