2015-09-08 20:07:57 +00:00
|
|
|
package rconfig
|
|
|
|
|
|
|
|
import (
|
2023-12-20 11:13:59 +00:00
|
|
|
"os"
|
2015-09-08 20:07:57 +00:00
|
|
|
|
2023-12-20 11:13:59 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2015-09-08 20:07:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// VarDefaultsFromYAMLFile reads contents of a file and calls VarDefaultsFromYAML
|
|
|
|
func VarDefaultsFromYAMLFile(filename string) map[string]string {
|
2023-12-20 11:13:59 +00:00
|
|
|
data, err := os.ReadFile(filename) //#nosec:G304 // Loading file from var is intended
|
2015-09-08 20:07:57 +00:00
|
|
|
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
|
|
|
|
}
|