diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-10-26 01:03:45 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-10-26 01:03:45 +0300 |
| commit | 04c812a02eac33cb01aee75069dc6f40f5733f0b (patch) | |
| tree | 0cb0537ad1f426396ac97924ba34d6cdaa5bb8b0 | |
| parent | creating new user db exec (diff) | |
| download | lphub-04c812a02eac33cb01aee75069dc6f40f5733f0b.tar.gz lphub-04c812a02eac33cb01aee75069dc6f40f5733f0b.tar.bz2 lphub-04c812a02eac33cb01aee75069dc6f40f5733f0b.zip | |
load .env once on main
| -rw-r--r-- | main.go | 11 |
1 files changed, 9 insertions, 2 deletions
| @@ -1,17 +1,24 @@ | |||
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "log" | ||
| 5 | "os" | ||
| 6 | |||
| 4 | "github.com/gin-gonic/contrib/static" | 7 | "github.com/gin-gonic/contrib/static" |
| 5 | "github.com/gin-gonic/gin" | 8 | "github.com/gin-gonic/gin" |
| 6 | "github.com/pektezol/leastportals/backend/controllers" | 9 | "github.com/joho/godotenv" |
| 7 | "github.com/pektezol/leastportals/backend/database" | 10 | "github.com/pektezol/leastportals/backend/database" |
| 8 | "github.com/pektezol/leastportals/backend/routes" | 11 | "github.com/pektezol/leastportals/backend/routes" |
| 9 | ) | 12 | ) |
| 10 | 13 | ||
| 11 | func main() { | 14 | func main() { |
| 12 | if controllers.GetEnvKey("ENV") == "PROD" { | 15 | if os.Getenv("ENV") == "PROD" { |
| 13 | gin.SetMode(gin.ReleaseMode) | 16 | gin.SetMode(gin.ReleaseMode) |
| 14 | } | 17 | } |
| 18 | err := godotenv.Load() | ||
| 19 | if err != nil { | ||
| 20 | log.Fatal("Error loading .env file") | ||
| 21 | } | ||
| 15 | router := gin.Default() | 22 | router := gin.Default() |
| 16 | database.ConnectDB() | 23 | database.ConnectDB() |
| 17 | router.Use(static.Serve("/", static.LocalFile("./frontend/dist", true))) | 24 | router.Use(static.Serve("/", static.LocalFile("./frontend/dist", true))) |