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
a9eccd5e
Unverified
Commit
a9eccd5e
authored
Oct 09, 2019
by
Eric_Lee
Committed by
GitHub
Oct 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] config的从环境变量解析非字符串值报错 (#97)
parent
12609824
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletion
+31
-1
config.go
pkg/config/config.go
+31
-1
No files found.
pkg/config/config.go
View file @
a9eccd5e
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"io/ioutil"
"log"
"log"
"os"
"os"
"strconv"
"strings"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -95,7 +96,36 @@ func (c *Config) LoadFromEnv() error {
...
@@ -95,7 +96,36 @@ func (c *Config) LoadFromEnv() error {
vSlice
:=
strings
.
Split
(
v
,
"="
)
vSlice
:=
strings
.
Split
(
v
,
"="
)
key
:=
vSlice
[
0
]
key
:=
vSlice
[
0
]
value
:=
vSlice
[
1
]
value
:=
vSlice
[
1
]
envMap
[
key
]
=
value
// 环境变量的值,非字符串类型的解析,需要另作处理
switch
key
{
case
"SFTP_SHOW_HIDDEN_FILE"
,
"REUSE_CONNECTION"
,
"UPLOAD_FAILED_REPLAY_ON_START"
:
switch
strings
.
ToLower
(
value
)
{
case
"true"
,
"on"
:
switch
key
{
case
"SFTP_SHOW_HIDDEN_FILE"
:
c
.
ShowHiddenFile
=
true
case
"REUSE_CONNECTION"
:
c
.
ReuseConnection
=
true
case
"UPLOAD_FAILED_REPLAY_ON_START"
:
c
.
UploadFailedReplay
=
true
}
case
"false"
,
"off"
:
switch
key
{
case
"SFTP_SHOW_HIDDEN_FILE"
:
c
.
ShowHiddenFile
=
false
case
"REUSE_CONNECTION"
:
c
.
ReuseConnection
=
false
case
"UPLOAD_FAILED_REPLAY_ON_START"
:
c
.
UploadFailedReplay
=
false
}
}
case
"SSH_TIMEOUT"
:
if
num
,
err
:=
strconv
.
Atoi
(
value
);
err
==
nil
{
c
.
SSHTimeout
=
time
.
Duration
(
num
)
}
default
:
envMap
[
key
]
=
value
}
}
}
envYAML
,
err
:=
yaml
.
Marshal
(
&
envMap
)
envYAML
,
err
:=
yaml
.
Marshal
(
&
envMap
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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