From ac006d5f1b7cbbbc8f2ed756170946b2f583fd26 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Wed, 8 Sep 2021 15:36:13 +0300 Subject: [PATCH] feat: hide seeds under env var --- .env | 3 --- .env.example | 1 + config/config.go | 13 +++++++++---- main.go | 4 +++- 4 files changed, 13 insertions(+), 8 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index d655d55..0000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -ENV=debug -PORT=3000 -POSTGRES_URL=postgres://localhost/micrach \ No newline at end of file diff --git a/.env.example b/.env.example index d655d55..7a62976 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ ENV=debug PORT=3000 +SEED_DB=true POSTGRES_URL=postgres://localhost/micrach \ No newline at end of file diff --git a/config/config.go b/config/config.go index 0902b9e..f4f68b3 100644 --- a/config/config.go +++ b/config/config.go @@ -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, } } diff --git a/main.go b/main.go index ad98e1b..980baa1 100644 --- a/main.go +++ b/main.go @@ -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 {