feat: hide seeds under env var

This commit is contained in:
Yanislav Igonin 2021-09-08 15:36:13 +03:00
parent d456be5e9a
commit ac006d5f1b
4 changed files with 13 additions and 8 deletions

3
.env
View File

@ -1,3 +0,0 @@
ENV=debug
PORT=3000
POSTGRES_URL=postgres://localhost/micrach

View File

@ -1,3 +1,4 @@
ENV=debug ENV=debug
PORT=3000 PORT=3000
SEED_DB=true
POSTGRES_URL=postgres://localhost/micrach POSTGRES_URL=postgres://localhost/micrach

View File

@ -9,6 +9,7 @@ import (
type AppConfig struct { type AppConfig struct {
Env string Env string
Port int Port int
SeedDb bool
} }
type DbConfig struct { type DbConfig struct {
@ -30,9 +31,13 @@ func getAppConfig() AppConfig {
panic(fmt.Sprintf("Could not parse %s to int", portString)) panic(fmt.Sprintf("Could not parse %s to int", portString))
} }
seedDbString := os.Getenv("SEED_DB")
seedDb := seedDbString == "true"
return AppConfig{ return AppConfig{
Env: env, Env: env,
Port: port, Port: port,
SeedDb: seedDb,
} }
} }

View File

@ -19,7 +19,9 @@ func main() {
Db.Init() Db.Init()
defer Db.Pool.Close() defer Db.Pool.Close()
gin.SetMode(Config.App.Env) gin.SetMode(Config.App.Env)
if Config.App.SeedDb {
Repositories.Seed() Repositories.Seed()
}
err := Utils.CreateUploadsFolder() err := Utils.CreateUploadsFolder()
if err != nil { if err != nil {