Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
appbase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pkg
appbase
Commits
8ee0233d
Commit
8ee0233d
authored
10 months ago
by
Tanawatra Chantaranit
Browse files
Options
Downloads
Patches
Plain Diff
chore: Add support for XML decoding in configs.go
parent
2af08b0f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
configs.go
+10
-1
10 additions, 1 deletion
configs.go
with
10 additions
and
1 deletion
configs.go
+
10
−
1
View file @
8ee0233d
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment