configer

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2019 License: MIT Imports: 15 Imported by: 1

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(v interface{}, cfgpaths ...string) error

func Parse

func Parse(data []byte, cfgpath string, val interface{}) (err error)

func ProcessTags

func ProcessTags(config interface{}) error

func Read

func Read(cfgpath string) ([]byte, error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL