conf

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 9 Imported by: 0

README

conf

conf file loader

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Decoders = map[string]Decoder{
	"JSON": {
		IDs: []string{"json"},
		ToJSON: func(content []byte) ([]byte, error) {
			return content, nil
		},
	},
	"YAML": {
		IDs: []string{"yml", "yaml"},
		ToJSON: func(content []byte) (bytes []byte, err error) {
			var m map[string]interface{}
			if err = yaml.Unmarshal(content, &m); err != nil {
				return
			}
			return json.Marshal(m)
		},
	},
	"TOML": {
		IDs: []string{"toml"},
		ToJSON: func(content []byte) (out []byte, err error) {
			var m map[string]interface{}
			if err = toml.Unmarshal(content, &m); err != nil {
				return
			}
			return json.Marshal(m)
		},
	},
}
View Source
var DefaultStorage = Dir("conf")

DefaultStorage default conf storage, from "conf" directory

Functions

func Load added in v0.2.0

func Load(name string, out interface{}) error

Load shortcut to DefaultStorage.Load

Types

type Decoder added in v0.2.0

type Decoder struct {
	IDs    []string
	ToJSON func(content []byte) (out []byte, err error)
}

func (Decoder) Decode added in v0.2.0

func (f Decoder) Decode(buf []byte, out interface{}) error

type Storage added in v0.2.0

type Storage interface {
	// Load load specified configuration into interface, tag 'json' and 'default' are supported
	Load(name string, out interface{}) error
}

Storage configuration storage, could be a local directory, a etcd endpoint or something else

func Dir added in v0.2.0

func Dir(dir string) Storage

Dir create a configuration storage from local directory

func Env added in v0.2.0

func Env(prefix string) Storage

Env create a configuration storage from env prefix

Jump to

Keyboard shortcuts

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