Skip to content
Small library for parsing (ala Rails) yaml config files.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
vendor
.gitignore
LICENSE
README.md
yamlconfig.go
yamlconfig_test.go

README.md

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

You can’t perform that action at this time.