Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
78cc46a7
Commit
78cc46a7
authored
Jun 11, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改加载配置文件从环境变量
parent
8b05a967
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
config.go
pkg/config/config.go
+7
-3
No files found.
pkg/config/config.go
View file @
78cc46a7
...
...
@@ -2,6 +2,7 @@ package config
import
(
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
...
...
@@ -81,13 +82,15 @@ func (c *Config) LoadFromJSON(body []byte) error {
}
func
(
c
*
Config
)
LoadFromEnv
()
error
{
envMap
:=
ma
p
[
string
]
string
{}
envMap
:=
ma
ke
(
map
[
string
]
string
)
env
:=
os
.
Environ
()
for
_
,
v
:=
range
env
{
vSlice
:=
strings
.
Split
(
v
,
"="
)
envMap
[
vSlice
[
0
]]
=
envMap
[
vSlice
[
1
]]
key
:=
vSlice
[
0
]
value
:=
vSlice
[
1
]
envMap
[
key
]
=
value
}
envYAML
,
err
:=
yaml
.
Marshal
(
envMap
)
envYAML
,
err
:=
yaml
.
Marshal
(
&
envMap
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error occur: %v"
,
err
)
}
...
...
@@ -100,6 +103,7 @@ func (c *Config) Load(filepath string) error {
return
err
}
err
=
c
.
LoadFromEnv
()
fmt
.
Println
(
c
.
CoreHost
)
return
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment