Skip to content

Commit ae81a78

Browse files
authored
refactor: replace hyphens and dots in environment variable keys (#25)
- Added import for the "strings" package - Defined a replacer for "-" and "." with "_" in variable "replacer" - Added a call to "SetEnvKeyReplacer" for the "viper" object in the "initConfig" function. fix #16
1 parent 98155ea commit ae81a78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cmd/cmd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"path"
9+
"strings"
910

1011
"github.com/appleboy/com/file"
1112
"github.com/spf13/cobra"
@@ -20,7 +21,8 @@ var rootCmd = &cobra.Command{
2021

2122
// Used for flags.
2223
var (
23-
cfgFile string
24+
cfgFile string
25+
replacer = strings.NewReplacer("-", "_", ".", "_")
2426
)
2527

2628
func init() {
@@ -66,6 +68,7 @@ func initConfig() {
6668
}
6769
}
6870

71+
viper.SetEnvKeyReplacer(replacer)
6972
viper.AutomaticEnv()
7073

7174
if err := viper.ReadInConfig(); err != nil {

0 commit comments

Comments
 (0)