# README
How to use
- Define a config structure, like below:
type RestfulConf struct {
Host string `json:",default=0.0.0.0"`
Port int
LogMode string `json:",options=[file,console]"`
Verbose bool `json:",optional"`
MaxConns int `json:",default=10000"`
MaxBytes int64 `json:",default=1048576"`
Timeout time.Duration `json:",default=3s"`
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
}
- Write the yaml, toml or json config file:
- yaml example
# most fields are optional or have default values
Port: 8080
LogMode: console
# you can use env settings
MaxBytes: ${MAX_BYTES}
- toml example
# most fields are optional or have default values
Port = 8_080
LogMode = "console"
# you can use env settings
MaxBytes = "${MAX_BYTES}"
- Load the config from a file:
// exit on error
var config RestfulConf
conf.MustLoad(configFile, &config)
// or handle the error on your own
var config RestfulConf
if err := conf.Load(configFile, &config); err != nil {
log.Fatal(err)
}
// enable reading from environments
var config RestfulConf
conf.MustLoad(configFile, &config, conf.UseEnv())
# Functions
Load loads config into v from file, .json, .yaml and .yml are acceptable.
LoadConfig loads config into v from file, .json, .yaml and .yml are acceptable.
LoadConfigFromJsonBytes loads config into v from content json bytes.
LoadConfigFromYamlBytes loads config into v from content yaml bytes.
LoadFromJsonBytes loads config into v from content json bytes.
LoadFromTomlBytes loads config into v from content toml bytes.
LoadFromYamlBytes loads config into v from content yaml bytes.
LoadProperties loads the properties into a properties configuration instance.
MustLoad loads config into v from path, exits on error.
NewProperties builds a new properties configuration structure.
UseEnv customizes the config to use environment variables.
# Structs
PropertyError represents a configuration error message.
# Interfaces
Properties interface provides the means to access configuration.
# Type aliases
No description provided by the author