go_conf/conf.go

32 lines
801 B
Go

package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"github.com/pkg/errors"
"r00t2.io/sysutils/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
}
}