Skip to content

GolubAlexander/config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

github.com/GolubAlexander/config

Description.

Library-helper to unmarshal a configuration file or a slice of bytes to the structure.

This library supports next types:

config.TypeJson
config.TypeYaml

Also 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")

How's to use.

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)
}

About

Lib to load configuration to the structure.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages