Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
10e2b7a2
Commit
10e2b7a2
authored
5 years ago
by
Patrick
Browse files
Options
Downloads
Patches
Plain Diff
change yaml unmarshal function to common package
parent
a32c98eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/yaml/yaml.go
+16
-9
16 additions, 9 deletions
common/yaml/yaml.go
config/base_config.go
+0
-25
0 additions, 25 deletions
config/base_config.go
with
16 additions
and
34 deletions
common/yaml/yaml.go
+
16
−
9
View file @
10e2b7a2
...
...
@@ -10,17 +10,24 @@ import (
"gopkg.in/yaml.v2"
)
func
UnmarshalYMLConfig
(
yamlFile
string
,
out
interface
{})
error
{
if
path
.
Ext
(
yamlFile
)
!=
".yml"
{
return
perrors
.
Errorf
(
"yamlFile name{%v} suffix must be .yml"
,
yamlFile
)
// loadYMLConfig Load yml config byte from file
func
loadYMLConfig
(
confProFile
string
)
([]
byte
,
error
)
{
if
len
(
confProFile
)
==
0
{
return
nil
,
perrors
.
Errorf
(
"application configure(provider) file name is nil"
)
}
confFileStream
,
err
:=
ioutil
.
ReadFile
(
yamlFile
)
if
err
!=
nil
{
return
perrors
.
Errorf
(
"
ioutil.ReadFile(file:%s) = error:%v"
,
yamlFile
,
perrors
.
WithStack
(
err
)
)
if
path
.
Ext
(
confProFile
)
!=
".yml"
{
return
nil
,
perrors
.
Errorf
(
"
application configure file name{%v} suffix must be .yml"
,
confProFile
)
}
err
=
yaml
.
Unmarshal
(
confFileStream
,
out
)
return
ioutil
.
ReadFile
(
confProFile
)
}
// unmarshalYMLConfig Load yml config byte from file , then unmarshal to object
func
UnmarshalYMLConfig
(
confProFile
string
,
out
interface
{})
error
{
confFileStream
,
err
:=
loadYMLConfig
(
confProFile
)
if
err
!=
nil
{
return
perrors
.
Errorf
(
"
yaml.Unmarshal() = error:%v"
,
perrors
.
WithStack
(
err
))
return
perrors
.
Errorf
(
"
ioutil.ReadFile(file:%s) = error:%v"
,
confProFile
,
perrors
.
WithStack
(
err
))
}
return
nil
return
yaml
.
Unmarshal
(
confFileStream
,
out
)
}
This diff is collapsed.
Click to expand it.
config/base_config.go
+
0
−
25
View file @
10e2b7a2
...
...
@@ -18,8 +18,6 @@
package
config
import
(
"io/ioutil"
"path"
"reflect"
"strconv"
"strings"
...
...
@@ -27,7 +25,6 @@ import (
import
(
perrors
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)
import
(
...
...
@@ -366,25 +363,3 @@ func initializeStruct(t reflect.Type, v reflect.Value) {
}
}
// loadYMLConfig Load yml config byte from file
func
loadYMLConfig
(
confProFile
string
)
([]
byte
,
error
)
{
if
len
(
confProFile
)
==
0
{
return
nil
,
perrors
.
Errorf
(
"application configure(provider) file name is nil"
)
}
if
path
.
Ext
(
confProFile
)
!=
".yml"
{
return
nil
,
perrors
.
Errorf
(
"application configure file name{%v} suffix must be .yml"
,
confProFile
)
}
return
ioutil
.
ReadFile
(
confProFile
)
}
// unmarshalYMLConfig Load yml config byte from file , then unmarshal to object
func
unmarshalYMLConfig
(
confProFile
string
,
out
interface
{})
error
{
confFileStream
,
err
:=
loadYMLConfig
(
confProFile
)
if
err
!=
nil
{
return
perrors
.
Errorf
(
"ioutil.ReadFile(file:%s) = error:%v"
,
confProFile
,
perrors
.
WithStack
(
err
))
}
return
yaml
.
Unmarshal
(
confFileStream
,
out
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
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