Skip to content

Golang Configuration tool that support INI, XML, YAML, JSON, HCL, TOML, Shell Environment

License

Notifications You must be signed in to change notification settings

wzshiming/configer

Repository files navigation

configer

Configuration loader that support INI, XML, YAML, JSON, HCL, TOML, Shell Environment

Install

go get -u -v github.com/wzshiming/configer

Usage

API Documentation

Examples

Priority: env > default > conf

package main

import (
	configer "gopkg.in/configer.v1"
	ffmt "gopkg.in/ffmt.v1"
)

func main() {
	examples1()
}

type BB struct {
	Hello   string `configer:"world"`            // Take the default value "world"
	Shell   string `configer:",env" env:"SHELL"` // Take the value of env
	EnvNone string `configer:",env" env:"NONE"`  // An empty env
}

type TT struct {
	LoadFilePath string `configer:"./examples1.json,env"`      // Loaded file path
	BB           BB     `configer:",load" load:"LoadFilePath"` // Load path field
}

func examples1() {
	b := BB{}

	configer.Load(&b)
	ffmt.Puts(b)
	/*
		{
		 Hello:   "world"
		 Shell:   "/bin/bash"
		 EnvNone: ""
		}
	*/

	configer.Load(&b, "./examples1.json")
	ffmt.Puts(b)
	/*
		{
		 Hello:   "json"
		 Shell:   "/bin/bash"
		 EnvNone: "env none"
		}
	*/

	t := TT{}
	configer.Load(&t)
	ffmt.Puts(t)
	/*
		{
		 LoadFilePath: "./examples1.json"
		 BB:           {
		  Hello:   "json"
		  Shell:   "/bin/bash"
		  EnvNone: "env none"
		 }
		}
	*/
}

With examples1.json:

{
    "Hello": "json",
    "Shell": "Priority default < env",
    "EnvNone": "env none"
}

MIT License

Pouch is licensed under the MIT License. See LICENSE for the full license text.

About

Golang Configuration tool that support INI, XML, YAML, JSON, HCL, TOML, Shell Environment

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages