mirror of
https://github.com/Luzifer/envrun.git
synced 2024-11-15 01:22:42 +00:00
28 lines
598 B
Go
28 lines
598 B
Go
|
package rconfig
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
|
||
|
"gopkg.in/yaml.v2"
|
||
|
)
|
||
|
|
||
|
// VarDefaultsFromYAMLFile reads contents of a file and calls VarDefaultsFromYAML
|
||
|
func VarDefaultsFromYAMLFile(filename string) map[string]string {
|
||
|
data, err := ioutil.ReadFile(filename)
|
||
|
if err != nil {
|
||
|
return make(map[string]string)
|
||
|
}
|
||
|
|
||
|
return VarDefaultsFromYAML(data)
|
||
|
}
|
||
|
|
||
|
// VarDefaultsFromYAML creates a vardefaults map from YAML raw data
|
||
|
func VarDefaultsFromYAML(in []byte) map[string]string {
|
||
|
out := make(map[string]string)
|
||
|
err := yaml.Unmarshal(in, &out)
|
||
|
if err != nil {
|
||
|
return make(map[string]string)
|
||
|
}
|
||
|
return out
|
||
|
}
|