From 712e2cfe8465c9e0e7f682ac1d4bd211d9504c90 Mon Sep 17 00:00:00 2001 From: wfhtqp Date: Sat, 26 Dec 2020 11:39:54 +0800 Subject: [PATCH] read config from env --- pkg/config/config.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 789ab10..c2b7ae4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,9 +1,11 @@ package config import ( + "log" + "strings" + "github.com/spf13/pflag" "github.com/spf13/viper" - "log" ) type Config struct { @@ -30,6 +32,8 @@ func SetupConfig() *Config { viper.AddConfigPath("/etc/next-terminal/") viper.AddConfigPath("$HOME/.next-terminal") viper.AddConfigPath(".") + viper.AutomaticEnv() + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) //pflag.String("mysql.hostname", "127.0.0.1", "mysql hostname") //pflag.Int("mysql.port", 3306, "mysql port")