go_conf/conf.go

31 lines
818 B
Go
Raw Normal View History

2020-09-12 01:25:44 -04:00
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
}
}