supporting env var for config.toml hostname
This commit is contained in:
parent
78d2ff6ec1
commit
7263332b1c
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -12,6 +13,11 @@ import (
|
|||
"github.com/toolkits/pkg/file"
|
||||
)
|
||||
|
||||
var envVarEscaper = strings.NewReplacer(
|
||||
`"`, `\"`,
|
||||
`\`, `\\`,
|
||||
)
|
||||
|
||||
type Global struct {
|
||||
PrintConfigs bool `toml:"print_configs"`
|
||||
Hostname string `toml:"hostname"`
|
||||
|
@ -108,10 +114,16 @@ func (c *ConfigType) GetHostname() string {
|
|||
|
||||
ret = strings.Replace(ret, "$hostname", name, -1)
|
||||
ret = strings.Replace(ret, "$ip", c.Global.IP, -1)
|
||||
ret = os.Expand(ret, getEnv)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func getEnv(key string) string {
|
||||
v := os.Getenv(key)
|
||||
return envVarEscaper.Replace(v)
|
||||
}
|
||||
|
||||
func GetInterval() time.Duration {
|
||||
if Config.Global.Interval <= 0 {
|
||||
return time.Second * 15
|
||||
|
|
Loading…
Reference in New Issue