-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
67 lines (55 loc) · 1.56 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gohoa
import (
"fmt"
"log"
"os"
"strings"
"sync"
"github.com/JeremyLoy/config"
)
type MainConfig struct {
MongoDBUrl string `config:"MONGODB_URI"`
MongoDBName string `config:"MONGODB_NAME"`
SlimMembersJson string `config:"SLIM_MEMBERS_JSON"`
SlimMembersJsonReval string `config:"SLIM_MEMBERS_JSON_REVAL"`
StreetsJson string `config:"STREETS_JSON"`
}
var (
mConfig MainConfig
configOnce sync.Once
)
func GetConfig() MainConfig {
configOnce.Do(func() {
var configBuilder *config.Builder
log.Println(" *--* RAW ENV *--*")
osEnvs := os.Environ()
for _, env := range osEnvs {
if strings.HasPrefix(env, "MONGODB_URI") {
env = fmt.Sprintf("%s%s", env[:strings.Index(env, "=")+1], "*****")
}
log.Println(" *--* ENV: ", env)
}
currEnv, found := os.LookupEnv("ENV_MODE")
if found && currEnv == "production" {
log.Println(" *--* Running in PRODUCTION mode, trying to load any .env.production file.")
configBuilder = config.FromOptional(".env.production")
} else {
log.Println(" *--* Running in DEVELOPMENT mode")
configBuilder = config.FromOptional(".env").FromOptional(".env.local")
}
err := configBuilder.FromEnv().To(&mConfig)
if err != nil {
log.Fatal("Error loading config: ", err)
}
})
return mConfig
}
// func getExistingFiles( filenames ...string) []string {
// var foundFileNames []string
// for _, filename := range filenames {
// if _, err := os.Stat(filename); err == nil {
// foundFileNames = append(foundFileNames, filename)
// }
// }
// return foundFileNames
// }