Library-helper to unmarshal a configuration file or a slice of bytes to the structure.
This library supports next types:
config.TypeJson
config.TypeYamlAlso the library has next types of errors:
ErrDataNull = errors.New("bytes must not be a null")
ErrDataEmpty = errors.New("bytes must not be an empty slice")
ErrNotImplemented = errors.New("file's format is not implemented")
ErrNotPointer = errors.New("param must be a pointer to a struct or a map")
ErrReadFile = errors.New("read config file")
ErrDecodeData = errors.New("decode config")Imports the library.
import "github.com/GolubAlexander/config"Describes type.
type conf struct {
Test string `json:"test" yaml:"test"`
}Makes function's calls to load from a file.
fileName:= "./example.json"
var cfg conf
if err := config.FromFile(&cfg, fileName); err != nil {
panic(err)
}Or to load from a slice of bytes:
confBytes := []byte("test: 'test'")
if err := config.FromBytes(&cfg, confBytes, config.TypeYaml); err != nil {
panic(err)
}