Skip to content

andrealbinop/go-yac

Repository files navigation

go-yac GoDoc Build Status Coverage Status Go Report

Yet Another Config provisioning library is strongly inspired by other similar projects, such as olebedev/config, micro/go-config and spf13/viper. Why not use those aforementioned libraries you may ask? You can still use, and that's the point. Sometimes projects start small and a simple YAML configuration file is enough. However, when they grow and you need more features, you may have problems adapting your code to use another library. Through a concise set of interfaces, the main goal of this project is to minimize the impact in your application's code when you need to change configuration provisioning code. Check here for more detail.

Installation

  • With go get:
go get -u github.com/andrealbinop/go-yac
dep ensure -add github.com/andrealbinop/go-yac

Usage

loader := ... // build your own config.Loader instance
var err error
var cfg config.Provider
if cfg, err = loader.Load(); err != nil {
    // error handling
}
// retrieve a value associated with "key"
value := cfg.String("key")

Custom Property Recovery

You can customize config.Provider property recovering routine, for instance, ignore camel case, as sampled below:

loader := ... // build your own config.Loader instance
var err error
var cfg config.Provider
if cfg, err = loader.Load(); err != nil {
    // error handling
} else if defaultLoader, ok := cfg.(provider.Default); ok {
	defaultLoader.ValueResolver = // Set Custom ValueResolver Ignored Camel Case
}

Development Notes