package icsconf import ( "encoding/xml" "fmt" "os" "sync" ) type AppInfo struct { XMLName xml.Name `xml:"AppInfo"` Speech Speech `xml:"Speech"` Directories Directories `xml:"Directories"` STT STTConf `xml:"STT"` } type Speech struct { Package string `xml:"Package"` ProtoPackage string `xml:"ProtoPackage"` } type Directories struct { PCMDirectory string `xml:"PCMDirectory"` WAVDirectory string `xml:"WAVDirectory"` LOGDirectory string `xml:"LOGDirectory"` RecDirectory string `xml:"RecDirectory"` } type STTConf struct { Value string `xml:"value,attr"` Name string `xml:"name,attr"` Port string `xml:"port,attr"` SrcIP string `xml:"srcIP,attr"` } var ( once sync.Once appInfo AppInfo ) func loadConfig() { file, err := os.Open("/home/prac/svc/icsbc/Appinfo.xml") if err != nil { fmt.Println("failed to open config file: ", err) return } defer file.Close() if err := xml.NewDecoder(file).Decode(&appInfo); err != nil { fmt.Println("failed to decode XML: ", err) return } } func initConfig() { once.Do(loadConfig) } func Getconfig() AppInfo { initConfig() return appInfo }