|
@@ -11,13 +11,13 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
var loaders = map[string]func([]byte, interface{}) error{
|
|
var loaders = map[string]func([]byte, interface{}) error{
|
|
- ".json": LoadConfigFromJsonBytes,
|
|
|
|
- ".yaml": LoadConfigFromYamlBytes,
|
|
|
|
- ".yml": LoadConfigFromYamlBytes,
|
|
|
|
|
|
+ ".json": LoadFromJsonBytes,
|
|
|
|
+ ".yaml": LoadFromYamlBytes,
|
|
|
|
+ ".yml": LoadFromYamlBytes,
|
|
}
|
|
}
|
|
|
|
|
|
-// LoadConfig loads config into v from file, .json, .yaml and .yml are acceptable.
|
|
|
|
-func LoadConfig(file string, v interface{}, opts ...Option) error {
|
|
|
|
|
|
+// Load loads config into v from file, .json, .yaml and .yml are acceptable.
|
|
|
|
+func Load(file string, v interface{}, opts ...Option) error {
|
|
content, err := ioutil.ReadFile(file)
|
|
content, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -40,14 +40,31 @@ func LoadConfig(file string, v interface{}, opts ...Option) error {
|
|
return loader(content, v)
|
|
return loader(content, v)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// LoadConfig loads config into v from file, .json, .yaml and .yml are acceptable.
|
|
|
|
+// Deprecated: use Load instead.
|
|
|
|
+func LoadConfig(file string, v interface{}, opts ...Option) error {
|
|
|
|
+ return Load(file, v, opts...)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// LoadFromJsonBytes loads config into v from content json bytes.
|
|
|
|
+func LoadFromJsonBytes(content []byte, v interface{}) error {
|
|
|
|
+ return mapping.UnmarshalJsonBytes(content, v)
|
|
|
|
+}
|
|
|
|
+
|
|
// LoadConfigFromJsonBytes loads config into v from content json bytes.
|
|
// LoadConfigFromJsonBytes loads config into v from content json bytes.
|
|
|
|
+// Deprecated: use LoadFromJsonBytes instead.
|
|
func LoadConfigFromJsonBytes(content []byte, v interface{}) error {
|
|
func LoadConfigFromJsonBytes(content []byte, v interface{}) error {
|
|
- return mapping.UnmarshalJsonBytes(content, v)
|
|
|
|
|
|
+ return LoadFromJsonBytes(content, v)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func LoadFromYamlBytes(content []byte, v interface{}) error {
|
|
|
|
+ return mapping.UnmarshalYamlBytes(content, v)
|
|
}
|
|
}
|
|
|
|
|
|
// LoadConfigFromYamlBytes loads config into v from content yaml bytes.
|
|
// LoadConfigFromYamlBytes loads config into v from content yaml bytes.
|
|
|
|
+// Deprecated: use LoadFromYamlBytes instead.
|
|
func LoadConfigFromYamlBytes(content []byte, v interface{}) error {
|
|
func LoadConfigFromYamlBytes(content []byte, v interface{}) error {
|
|
- return mapping.UnmarshalYamlBytes(content, v)
|
|
|
|
|
|
+ return LoadFromYamlBytes(content, v)
|
|
}
|
|
}
|
|
|
|
|
|
// MustLoad loads config into v from path, exits on error.
|
|
// MustLoad loads config into v from path, exits on error.
|