Skip to content

Small library for parsing (ala Rails) yaml config files.

License

Notifications You must be signed in to change notification settings

sent-hil/go-yamlconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-yamlconfig

This is a small library for parsing yaml config files. The main advantage of this over plain yaml parsing is this library falls back on defaults block when getting key value, ie the way Rails defines its yaml config files.

Usage

Initialize client:

var exampleConfig = `
defaults: &defaults
 env: development

development:
 <<: *defaults // inherits from defaults

production:
 <<: *defaults   // inherits from defaults
 env: production // overrides defaults for this specific key
`

config, err := New([]byte(exampleConfig))
if err != nil {
  return err
}

Get default environment (development) config:

val, err := config.GetString("database")
if err != nil {
  return err
}

fmt.Println(val) // development

Get config from another environment:

// override environment
config.SetEnv(Production)
val, err = config.GetString("database")
if err != nil {
  return err
}

fmt.Println(val) // production

If config is not string, Get can be used to return an interface{} value:

val1, err := config.Get("database")
if err != nil {
  return err
}

fmt.Println(val) // production

Install

go get github.com/sent-hil/go-yamlconfig

Test

go test

About

Small library for parsing (ala Rails) yaml config files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages