Skip to content
Snippets Groups Projects
Commit 8ee0233d authored by Tanawatra Chantaranit's avatar Tanawatra Chantaranit
Browse files

chore: Add support for XML decoding in configs.go

parent 2af08b0f
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package appbase
import (
"encoding/json"
"encoding/xml"
"io"
"os"
"path/filepath"
......@@ -25,10 +26,12 @@ func decodeFile(cfg interface{}, filename string) error {
ext = filepath.Ext(filename)
)
switch ext {
case ".yaml":
case ".yaml", ".yml":
dec = getYAMLDecoder
case ".json":
dec = getJSONDecoder
case ".xml":
dec = getXMLDecoder
}
// Load config
cfgFile, err := os.Open(filename)
......@@ -67,6 +70,12 @@ func getJSONDecoder(r io.Reader) decoder.Interface {
return jsonDecoder
}
func getXMLDecoder(r io.Reader) decoder.Interface {
xmlDecoder := xml.NewDecoder(r)
xmlDecoder.Strict = true
return xmlDecoder
}
func getFileNameLocal(filename string) string {
fileExt := filepath.Ext(filename)
fileNoExt := strings.TrimSuffix(filename, fileExt)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment