mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: proper parsing of environment variables
This commit is contained in:
parent
7b486b390e
commit
91a4bb2db3
2
go.mod
2
go.mod
@ -14,8 +14,6 @@ require (
|
||||
github.com/rs/cors v1.7.0
|
||||
github.com/rubenv/sql-migrate v0.0.0-20200402132117-435005d389bc
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
github.com/t-tiger/gorm-bulk-insert v0.0.0-20191014134946-beb77b81825f
|
||||
google.golang.org/appengine v1.6.5 // indirect
|
||||
gopkg.in/ini.v1 v1.50.0
|
||||
)
|
||||
|
19
main.go
19
main.go
@ -40,20 +40,15 @@ func readConfig() *models.Config {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// TODO: Use jinzhu/configor or so
|
||||
env, _ := os.LookupEnv("ENV")
|
||||
dbType, valid := os.LookupEnv("WAKAPI_DB_TYPE")
|
||||
dbUser, valid := os.LookupEnv("WAKAPI_DB_USER")
|
||||
dbPassword, valid := os.LookupEnv("WAKAPI_DB_PASSWORD")
|
||||
dbHost, valid := os.LookupEnv("WAKAPI_DB_HOST")
|
||||
dbName, valid := os.LookupEnv("WAKAPI_DB_NAME")
|
||||
dbPortStr, valid := os.LookupEnv("WAKAPI_DB_PORT")
|
||||
env := utils.LookupFatal("ENV")
|
||||
dbType := utils.LookupFatal("WAKAPI_DB_TYPE")
|
||||
dbUser := utils.LookupFatal("WAKAPI_DB_USER")
|
||||
dbPassword := utils.LookupFatal("WAKAPI_DB_PASSWORD")
|
||||
dbHost := utils.LookupFatal("WAKAPI_DB_HOST")
|
||||
dbName := utils.LookupFatal("WAKAPI_DB_NAME")
|
||||
dbPortStr := utils.LookupFatal("WAKAPI_DB_PORT")
|
||||
dbPort, err := strconv.Atoi(dbPortStr)
|
||||
|
||||
if !valid {
|
||||
log.Fatal("Environment variables missing or invalid.")
|
||||
}
|
||||
|
||||
cfg, err := ini.Load("config.ini")
|
||||
if err != nil {
|
||||
log.Fatalf("Fail to read file: %v", err)
|
||||
|
14
utils/environment.go
Normal file
14
utils/environment.go
Normal file
@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LookupFatal(key string) string {
|
||||
v, ok := os.LookupEnv(key)
|
||||
if !ok {
|
||||
log.Fatalf("missing env variable '%s'", key)
|
||||
}
|
||||
return v
|
||||
}
|
@ -1 +1 @@
|
||||
1.2.0
|
||||
1.2.1
|
Loading…
Reference in New Issue
Block a user