config

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendStringArgs

func AppendStringArgs(cmd *cobra.Command, args []string, key string) []string

AppendStringArgs appends viper value to existing args slice

func AppendStringArgsf

func AppendStringArgsf(format string, cmd *cobra.Command, args []string, key string) []string

AppendStringArgsf appends viper value to existing args slice with optional formatted output with key and value

func AppendStringSplitArgs

func AppendStringSplitArgs(cmd *cobra.Command, args []string, key string, splitPattern string) []string

AppendSplitArgs appends viper value to existing args slice after splitting them by splitPattern (default regex whitespace)

func BuildEnvKey added in v1.5.0

func BuildEnvKey(cmd *cobra.Command, envPrefix string, keyName string) string

BuildEnvKey returns a fully constructed environment variable name

func CheckRequiredFlags

func CheckRequiredFlags(cmd *cobra.Command, requiredFlags []string) error

CheckRequiredFlags exits with error when one ore more required flags are not set

func PrefixKey

func PrefixKey(cmd *cobra.Command, keyName string) string

PrefixKey prepends current and parent Use to specified key name

func ViperBindPFlag

func ViperBindPFlag(cmd *cobra.Command, name string)

ViperBindPFlag is a convenience wrapper over viper.BindPFlag for local flags

func ViperBindPFlagSet

func ViperBindPFlagSet(cmd *cobra.Command, flags *pflag.FlagSet)

ViperBindPFlagSet is a convenience wrapper over viper.BindPFlag for local FlagSet

if flags is nil, the cmd.Flags() will be used

func ViperBindPersistentPFlag

func ViperBindPersistentPFlag(cmd *cobra.Command, name string)

ViperBindPersistentPFlag is a convenience wrapper over viper.BindPFlag for persistent flags

func ViperGetBool

func ViperGetBool(cmd *cobra.Command, key string) bool

ViperGetBool is a convenience wrapper that returns the value associated with the key as a boolean.

func ViperGetDuration

func ViperGetDuration(cmd *cobra.Command, key string) time.Duration

ViperGetDuration is a convenience wrapper that returns the value associated with the key as a duration.

func ViperGetFloat64 added in v1.4.3

func ViperGetFloat64(cmd *cobra.Command, key string) float64

ViperGetFloat64 is a convenience wrapper that returns the value associated with the key as a float64.

func ViperGetInt

func ViperGetInt(cmd *cobra.Command, key string) int

ViperGetInt is a convenience wrapper that returns the value associated with the key as an integer.

func ViperGetSizeInBytes added in v1.4.3

func ViperGetSizeInBytes(cmd *cobra.Command, key string) uint

ViperGetSizeInBytes is a convenience wrapper that returns the size of the value associated with the given key

func ViperGetString

func ViperGetString(cmd *cobra.Command, key string) string

ViperGetString is a convenience wrapper that returns the value associated with the key as a string.

func ViperGetStringMap added in v1.4.3

func ViperGetStringMap(cmd *cobra.Command, key string) map[string]interface{}

ViperGetStringMap is a convenience wrapper that returns the value associated with the key as a map of interfaces.

func ViperGetStringMapString added in v1.4.3

func ViperGetStringMapString(cmd *cobra.Command, key string) map[string]string

ViperGetStringMapString is a convenience wrapper that returns the value associated with the key as a map of strings.

func ViperGetStringMapStringSlice added in v1.4.3

func ViperGetStringMapStringSlice(cmd *cobra.Command, key string) map[string][]string

ViperGetStringMapStringSlice is a convenience wrapper that returns the value associated with the key as a map to a slice of strings.

func ViperGetStringSlice added in v1.4.3

func ViperGetStringSlice(cmd *cobra.Command, key string) []string

ViperGetStringSlice is a convenience wrapper that returns the value associated with the key as a slice of strings.

func ViperGetTime added in v1.4.3

func ViperGetTime(cmd *cobra.Command, key string) time.Time

ViperGetTime is a convenience wrapper that returns the value associated with the key as time.

func ViperIsSet

func ViperIsSet(cmd *cobra.Command, key string) bool

ViperIsSet is a convenience wrapper returning true if a key is set. Case insensitive for keys.

func ViperSet

func ViperSet(cmd *cobra.Command, key, value string)

ViperSet is a convenience wrapper setting an override value for specified key

Types

type Option added in v1.5.0

type Option func(*Options)

func WithConfigName added in v1.5.0

func WithConfigName(configName string) Option

func WithConfigType added in v1.5.0

func WithConfigType(configType string) Option

func WithEnvPrefix added in v1.5.0

func WithEnvPrefix(envPrefix string) Option

func WithFlags added in v1.5.0

func WithFlags(flags *pflag.FlagSet) Option

func WithLogFormatKey added in v1.5.0

func WithLogFormatKey(logFormatKey string) Option

func WithLogLevelKey added in v1.5.0

func WithLogLevelKey(logLevelKey string) Option

func WithUserConfigPaths added in v1.5.0

func WithUserConfigPaths(userConfigPaths []string) Option

type Options added in v1.5.0

type Options struct {
	EnvPrefix       string
	ConfigType      string
	ConfigName      string
	UserConfigPaths []string
	LogLevel        string
	LogLevelKey     string
	LogFormat       string
	LogFormatKey    string
	Flags           *pflag.FlagSet
}

func NewOptions added in v1.5.0

func NewOptions(options ...Option) (*Options, error)

NewOptions sets default Options overriding with options

func (*Options) InitConfig added in v1.5.0

func (opts *Options) InitConfig() error

InitConfig reads in config file and ENV variables if set.

Jump to

Keyboard shortcuts

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