readd directory

This commit is contained in:
Antoine Ouvrard
2023-03-09 17:29:50 +01:00
parent be5eb0822b
commit 3fe3b6e90a
23 changed files with 1016 additions and 0 deletions
@@ -0,0 +1,61 @@
package zimbra
import (
"bytes"
"encoding/xml"
"io"
"os"
"path/filepath"
)
type Localconfig struct {
XMLName xml.Name `xml:"localconfig"`
LocalconfigKeys []LocalconfigKey `xml:"key"`
}
type LocalconfigKey struct {
XMLName xml.Name `xml:"key"`
Name string `xml:"name,attr"`
Value string `xml:"value"`
}
var localConfigData map[string]string
func ReadLocalConfig(basePath string) error {
filePath := filepath.Join(basePath, "conf/localconfig.xml")
xmlFile, errOpen := os.Open(filePath)
if errOpen != nil {
return errOpen
}
defer xmlFile.Close()
var buf bytes.Buffer
_, errCopy := io.Copy(&buf, xmlFile)
if errCopy != nil {
return errCopy
}
var data Localconfig
errXml := xml.Unmarshal(buf.Bytes(), &data)
if errXml != nil {
return errXml
}
localConfigData = make(map[string]string)
for _, key := range data.LocalconfigKeys {
localConfigData[key.Name] = key.Value
}
return nil
}
func Get(param string) (string, bool) {
value, ok := localConfigData[param]
return value, ok
}