Documentation
¶
Index ¶
- func AddConfigPath(in string)
- func BindAllFlags(fs *pflag.FlagSet, cfg any, opts ...viper.DecoderConfigOption) (*pflag.FlagSet, error)
- func BindEnvs(prefix, keyDelimiter, envDelimiter string)
- func BindPFlag(key string, flag *pflag.Flag) error
- func BindPFlags(flags *pflag.FlagSet) error
- func ConfigFileUsed() string
- func GetBool(name string, def bool) bool
- func GetFloat64(name string, def float64) float64
- func GetInt(name string, def int) int
- func GetInt64(name string, def int64) int64
- func GetString(name string, def string) string
- func GetStrings(name string, def []string) []string
- func GetViper() *viper.Viper
- func InitConfigFile(cfgFile, cfgFilePath, cfgFileName, cfgFileType string) error
- func ParseConfig(cfg any, envPrefix string, cfgFile string, opts ...viper.DecoderConfigOption) error
- func ReadInConfig() error
- func SetConfigFile(in string)
- func SetConfigName(in string)
- func SetConfigType(in string)
- func Unmarshal(cfg any, opts ...viper.DecoderConfigOption) (err error)
- type ViperX
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConfigPath ¶
func AddConfigPath(in string)
AddConfigPath adds a new path for viper to search for the configuration file in.
func BindAllFlags ¶
func BindAllFlags(fs *pflag.FlagSet, cfg any, opts ...viper.DecoderConfigOption) (*pflag.FlagSet, error)
BindAllFlags 添加cfg结构体中vx_flag标记的Flag,并返回完整的FlagSet (推荐)若未定义name,name解析为cfg结构体成员名,多级使用"."相连 否则,解析为name 若fs为空,会初始化一个新的
func BindEnvs ¶
func BindEnvs(prefix, keyDelimiter, envDelimiter string)
BindEnvs sets up environment variables to override configuration values. It takes a prefix for environment variable names, a delimiter for configuration keys, and an environment delimiter for replacing in keys.
func BindPFlags ¶
func ConfigFileUsed ¶
func ConfigFileUsed() string
func GetBool ¶
GetBool retrieves a boolean value from the configuration. It returns a default value if the key is not set.
func GetFloat64 ¶
GetFloat64 retrieves a float64 value from the configuration. It returns a default value if the key is not set.
func GetInt ¶
GetInt retrieves an integer value from the configuration. It returns a default value if the key is not set.
func GetInt64 ¶
GetInt64 retrieves an int64 value from the configuration. It returns a default value if the key is not set.
func GetString ¶
GetString retrieves a string value from the configuration. It returns a default value if the key is not set.
func GetStrings ¶
GetStrings retrieves a slice of strings from the configuration. It returns a default value if the key is not set.
func InitConfigFile ¶
InitConfigFile initializes configuration files using viper. It takes paths to configuration file, file name, and file type. If a configuration file is found, it will be read into viper.
func ParseConfig ¶
func ParseConfig(cfg any, envPrefix string, cfgFile string, opts ...viper.DecoderConfigOption) error
ParseConfig parse config in order by cli flags, env, config, default
func ReadInConfig ¶
func ReadInConfig() error
func SetConfigFile ¶
func SetConfigFile(in string)
SetConfigFile sets the path to the configuration file.
func SetConfigName ¶
func SetConfigName(in string)
SetConfigName sets the name for the configuration file.
func SetConfigType ¶
func SetConfigType(in string)
SetConfigType sets the type of the configuration file.