github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/config/common.go (about) 1 package config 2 3 import ( 4 "os" 5 6 "github.com/pkg/errors" 7 "github.com/tidwall/gjson" 8 ) 9 10 // ReadConfigFile reads config from file 11 func ReadConfigFile(path string) (string, error) { 12 if path == "" { 13 return "", errors.New("config path cannot be empty") 14 } 15 config, err := os.ReadFile(path) 16 if err != nil { 17 return "", errors.Wrapf(err, "unable to read config file") 18 } 19 20 return string(config), nil 21 } 22 23 // ParseConfigToJSONMap parses configuration into json object 24 func ParseConfigToJSONMap(configData string) (map[string]gjson.Result, error) { 25 if ok := gjson.Valid(configData); !ok { 26 return nil, errors.New("failed to validate config data") 27 } 28 29 result := gjson.Parse(configData) 30 return result.Map(), nil 31 }