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
PORT=3000
SEED_DB=true
POSTGRES_URL=postgres://localhost/micrach

View File

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

View File

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