Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

firmeve/go-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Point syntax configuration

Build Status Coverage Status GitHub license

Configuration package that supports multi-level dot syntax read write

Basic usage

Install

go get -u github.com/firmeve/go-config

Instantiation

config, err := NewConfig(directory)
if err != nil {
    panic(err.Error())
}

Note: config is a singleton object

Set

// 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())
}

Get

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 the key value specified by the default section, such as: Get("app.t")
  • If key is a section, return a *ini.Section object, such as: Get("app.section.sub")

GetDefault

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)

All

Get all configurations, return map[string]*ini.File

configs := config.All()

Thanks

Development package based on go-ini/ini

Releases

No releases published

Packages

No packages published

Languages