mirror of
https://github.com/Luzifer/rconfig.git
synced 2024-11-08 16:00:10 +00:00
27 lines
638 B
Go
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
|
|
}
|