Documentation ¶
Overview ¶
Package config provides an interface and initialization function for handling configuration values stored as JSON. The JSON structure is defined by a user configurable struct which implements Configurator. Nest Configurator instances by calling Init within the parent's InitPost.
Example ¶
package main import ( "fmt" "github.com/codemodus/config" ) func main() { myConf := &struct { *config.Config SampleText string TestText string }{} if err := config.Init(myConf, "testdata/config.json"); err != nil { fmt.Println(err) } fmt.Println(myConf.SampleText) fmt.Println(myConf.TestText) }
Output: sampled tested
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultConfDir is the configuration directory fallback. DefaultConfDir = defaultConfDir() // DefaultFilename is the configuration filename fallback. DefaultFilename = "config.cnf" // DefaultLibDir is the lib directory fallback. DefaultLibDir = defaultLibDir() // ErrBadData indicates that the relevant data is not valid JSON or TOML. ErrBadData = errors.New("provided data is not valid JSON or TOML") )
Functions ¶
func Init ¶
func Init(c Configurator, file string) (err error)
Init decodes the provided JSON file into the provided Configurator.
Types ¶
type Config ¶
type Config struct{}
Config is provided for embedding default methods needed to satisfy the Configurator interface.
type Configurator ¶
type Configurator interface { // InitPost should contain any post initialization logic to be applied to // the Configurator, and return any processing errors. InitPost() error }
Configurator defines the basic functionality required to work with config.
Click to show internal directories.
Click to hide internal directories.