1
0
Fork 0
mirror of https://github.com/Luzifer/rconfig.git synced 2024-11-09 00:10:07 +00:00
rconfig/vardefault_providers.go
Knut Ahlers c1c878fab9
Update deps, fix linter errors, bump min Go version
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2023-12-20 12:13:59 +01:00

27 lines
638 B
Go

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