viperx

package
v1.3.32 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

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 BindPFlag

func BindPFlag(key string, flag *pflag.Flag) error

func BindPFlags

func BindPFlags(flags *pflag.FlagSet) error

func ConfigFileUsed

func ConfigFileUsed() string

func GetBool

func GetBool(name string, def bool) bool

GetBool retrieves a boolean value from the configuration. It returns a default value if the key is not set.

func GetFloat64

func GetFloat64(name string, def float64) float64

GetFloat64 retrieves a float64 value from the configuration. It returns a default value if the key is not set.

func GetInt

func GetInt(name string, def int) int

GetInt retrieves an integer value from the configuration. It returns a default value if the key is not set.

func GetInt64

func GetInt64(name string, def int64) int64

GetInt64 retrieves an int64 value from the configuration. It returns a default value if the key is not set.

func GetString

func GetString(name string, def string) string

GetString retrieves a string value from the configuration. It returns a default value if the key is not set.

func GetStrings

func GetStrings(name string, def []string) []string

GetStrings retrieves a slice of strings from the configuration. It returns a default value if the key is not set.

func GetViper

func GetViper() *viper.Viper

func InitConfigFile

func InitConfigFile(cfgFile, cfgFilePath, cfgFileName, cfgFileType string) error

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.

func Unmarshal

func Unmarshal(cfg any, opts ...viper.DecoderConfigOption) (err error)

Unmarshal decodes the configuration into a struct using viper.Unmarshal. It accepts any type of rawVal where configuration data will be stored, and opts for decoder options.

Types

type ViperX

type ViperX struct {
	// contains filtered or unexported fields
}

func New

func New() *ViperX

func (*ViperX) BindFlags

func (o *ViperX) BindFlags(fs *pflag.FlagSet) error

Jump to

Keyboard shortcuts

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