Configuration package that supports multi-level dot syntax read write
go get -u github.com/firmeve/go-config
config, err := NewConfig(directory)
if err != nil {
panic(err.Error())
}
Note:
config
is a singleton object
// Set or add a value for the key
err := config.Set("app.key", "value")
if err != nil {
panic(err.Error())
}
// Set or add a value for a multi-section key
err := config.Set("app.section.key", "value")
if err != nil {
panic(err.Error())
}
value, err := config.Get("app.section.key")
if err != nil {
panic(err.Error())
}
fmt.Println("%#v",value)
fmt.Println(value.(*ini.Key).Value())
- If
key
is the file name, return a*ini.File
object, such as:Get("app")
- If
key
has only one dot separation, it returns thekey
value specified by the defaultsection
, such as:Get("app.t")
- If
key
is asection
, return a*ini.Section
object, such as:Get("app.section.sub")
Same as Get
, but if the value accessed does not exist, the default value will be used instead of err
to mask the error output.
value := config.GetDefault("app.section.key", "default")
fmt.Println("%s",value)
Get all configurations, return map[string]*ini.File
configs := config.All()
Development package based on go-ini/ini