diff --git a/go.mod b/go.mod index 863253e..afece83 100644 --- a/go.mod +++ b/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 ) diff --git a/main.go b/main.go index 2a66cb7..bb7a3e9 100644 --- a/main.go +++ b/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) diff --git a/utils/environment.go b/utils/environment.go new file mode 100644 index 0000000..b225228 --- /dev/null +++ b/utils/environment.go @@ -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 +} diff --git a/version.txt b/version.txt index 867e524..cb174d5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.0 \ No newline at end of file +1.2.1 \ No newline at end of file