package conf import ( "encoding/xml" `fmt` "io/ioutil" `github.com/pkg/errors` "git.square-r00t.net/go_sysutils.git/paths" ) // ParseConf parses the path of the XML config provided at confPath ptr by using the confStruct struct ptr. // If an XSD is found in the struct, it will be validated against (returning pass/fail as bool), otherwise always return true unless error. func ParseConf(confPath *string, confStruct *struct{}) (bool, error) { exists, err := paths.RealPathExists(confPath) if !exists { return false, errors.New(fmt.Sprintf("Configuration path %v does not exist", *confPath)) } else if err != nil { return false, err } xmlDoc, err := ioutil.ReadFile(*confPath) if err != nil { return false, err } err = xml.Unmarshal(xmlDoc, confStruct) if err != nil { return false, err } }