Documentation ¶
Overview ¶
Config is a simple k/v config package to load config items from files, command line flags and enviroment variables.
Installation
go get gitea.com/lunny/config
Load config items
// This will load configs from files, envs, flags and will be overrided according files < envs < flags cfgs, err := config.Load(myconfigfile1, myconfigfile2) // Or if you want to ignore the error when files do not exist. cfgs, err := config.LoadIfExist(myconfigfile)
Usage
cfgs.Get(key) cfgs.Set(key, value) cfgs.MustString(key) cfgs.MustInt(key)
Index ¶
- Variables
- func LoadEnvs() map[string]string
- func LoadFlags() map[string]string
- type Config
- func (config *Config) Get(key string) string
- func (config *Config) GetBool(key string) (bool, error)
- func (config *Config) GetFloat64(key string) (float64, error)
- func (config *Config) GetInt(key string) (int, error)
- func (config *Config) GetSlice(key, sep string) []string
- func (config *Config) Has(key string) bool
- func (config *Config) Map() map[string]string
- func (config *Config) MustBool(key string, defaultVal ...bool) bool
- func (config *Config) MustFloat64(key string, defaultVal ...float64) float64
- func (config *Config) MustInt(key string, defaultVal ...int) int
- func (config *Config) MustInt64(key string, defaultVal ...int64) int64
- func (config *Config) MustString(key string, defaultVal ...string) string
- func (config *Config) Set(key, value string)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrConfigFileNotExist reprents the error ErrConfigFileNotExist = errors.New("config file is not exist") )
Functions ¶
Types ¶
type Config ¶
Config config object
func LoadIfExist ¶
LoadIfExist will load files if exist and then environments and then flags
func (*Config) GetFloat64 ¶
GetFloat64 returns item value as float64
func (*Config) MustFloat64 ¶
MustFloat64 always returns item value as float64
func (*Config) MustString ¶
MustString return the string value
Click to show internal directories.
Click to hide internal directories.