Unverified Commit a9eccd5e authored by Eric_Lee's avatar Eric_Lee Committed by GitHub

[Bugfix] config的从环境变量解析非字符串值报错 (#97)

parent 12609824
...@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment