fix golint issues in core/conf (#476)
This commit is contained in:
@@ -16,6 +16,7 @@ var loaders = map[string]func([]byte, interface{}) error{
|
|||||||
".yml": LoadConfigFromYamlBytes,
|
".yml": LoadConfigFromYamlBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadConfig loads config into v from file, .json, .yaml and .yml are acceptable.
|
||||||
func LoadConfig(file string, v interface{}, opts ...Option) error {
|
func LoadConfig(file string, v interface{}, opts ...Option) error {
|
||||||
content, err := ioutil.ReadFile(file)
|
content, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -39,14 +40,17 @@ func LoadConfig(file string, v interface{}, opts ...Option) error {
|
|||||||
return loader(content, v)
|
return loader(content, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadConfigFromJsonBytes loads config into v from content json bytes.
|
||||||
func LoadConfigFromJsonBytes(content []byte, v interface{}) error {
|
func LoadConfigFromJsonBytes(content []byte, v interface{}) error {
|
||||||
return mapping.UnmarshalJsonBytes(content, v)
|
return mapping.UnmarshalJsonBytes(content, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadConfigFromYamlBytes loads config into v from content yaml bytes.
|
||||||
func LoadConfigFromYamlBytes(content []byte, v interface{}) error {
|
func LoadConfigFromYamlBytes(content []byte, v interface{}) error {
|
||||||
return mapping.UnmarshalYamlBytes(content, v)
|
return mapping.UnmarshalYamlBytes(content, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustLoad loads config into v from path, exits on error.
|
||||||
func MustLoad(path string, v interface{}, opts ...Option) {
|
func MustLoad(path string, v interface{}, opts ...Option) {
|
||||||
if err := LoadConfig(path, v, opts...); err != nil {
|
if err := LoadConfig(path, v, opts...); err != nil {
|
||||||
log.Fatalf("error: config file %s, %s", path, err.Error())
|
log.Fatalf("error: config file %s, %s", path, err.Error())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Option defines the method to customize the config options.
|
||||||
Option func(opt *options)
|
Option func(opt *options)
|
||||||
|
|
||||||
options struct {
|
options struct {
|
||||||
@@ -8,6 +9,7 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// UseEnv customizes the config to use environment variables.
|
||||||
func UseEnv() Option {
|
func UseEnv() Option {
|
||||||
return func(opt *options) {
|
return func(opt *options) {
|
||||||
opt.env = true
|
opt.env = true
|
||||||
|
|||||||
Reference in New Issue
Block a user