Skip to content

Commit 2fd3f68

Browse files
committed
Refactor code
1 parent 12d1dba commit 2fd3f68

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ func LoadConfig(envName string, c interface{}, fileNames ...string) error {
3232
env := os.Getenv(envName)
3333
return LoadConfigWithEnv("", "", env, c, fileNames...)
3434
}
35-
// Load function will read config from environment or config file.
35+
36+
// LoadConfigWithEnv function will read config from environment or config file.
3637
func LoadConfigWithEnv(parentPath string, directory string, env string, c interface{}, fileNames ...string) error {
3738
viper.AutomaticEnv()
3839
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
3940
viper.SetConfigType("yaml")
4041

4142
fileCount := len(fileNames)
42-
if fileCount > 0 {
43+
if fileCount > 0 {
4344
if len(parentPath) == 0 && len(directory) == 0 {
4445
viper.AddConfigPath("./")
4546
} else {
@@ -59,7 +60,7 @@ func LoadConfigWithEnv(parentPath string, directory string, env string, c interf
5960
}
6061
}
6162

62-
for i:=1; i< fileCount; i++ {
63+
for i := 1; i < fileCount; i++ {
6364
viper.SetConfigName(fileNames[i])
6465
if er2b := viper.MergeInConfig(); er2b != nil {
6566
switch er2b.(type) {
@@ -109,7 +110,7 @@ func LoadConfigWithEnv(parentPath string, directory string, env string, c interf
109110
return er4
110111
}
111112

112-
// bindEnvs function will bind ymal file to struc model
113+
// BindEnvs function will bind ymal file to struc model
113114
func BindEnvs(conf interface{}, parts ...string) error {
114115
ifv := reflect.Indirect(reflect.ValueOf(conf))
115116
ift := reflect.TypeOf(ifv)
@@ -228,7 +229,7 @@ func LoadFileWithPath(parentPath string, directory string, env string, filename
228229
if indexDot >= 0 {
229230
file := "./" + filename[0:indexDot] + "-" + env + filename[indexDot:]
230231
if !fileExists(file) {
231-
file = "./" + parentPath + "/" + filename[0:indexDot] + "-" + env + filename[indexDot:]
232+
file = "./" + parentPath + "/" + filename[0:indexDot] + "-" + env + filename[indexDot:]
232233
}
233234
if fileExists(file) {
234235
return ioutil.ReadFile(file)

0 commit comments

Comments
 (0)