Skip to content

Commit

Permalink
🎨 refactor: Improve Gin mode setting and logging
Browse files Browse the repository at this point in the history
- Move Gin mode setting to initializeApp function
- Add logging for APP_ENV value in NewEnv function
- Remove redundant Gin mode setting from main function
  • Loading branch information
yuminn-k committed Oct 19, 2024
1 parent 9748a49 commit c37666a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bootstrap/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func NewEnv() (*Env, error) {
log.Println("The App is running in development env")
}

log.Printf("APP_ENV is set to: %s", env.AppEnv)

return env, nil
}

Expand Down
19 changes: 12 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ func main() {
}
defer app.CloseDBConnection()

if app.Env.AppEnv == "release" {
gin.SetMode(gin.ReleaseMode)
} else {
gin.SetMode(gin.DebugMode)
}

if err := checkDatabaseConnection(app); err != nil {
log.Fatalf("Failed to connect to the database: %v", err)
}
Expand All @@ -36,7 +30,18 @@ func main() {
}

func initializeApp() (*bootstrap.Application, error) {
return bootstrap.App()
app, err := bootstrap.App()
if err != nil {
return nil, err
}

if app.Env.AppEnv == "release" {
gin.SetMode(gin.ReleaseMode)
} else {
gin.SetMode(gin.DebugMode)
}

return app, nil
}

func setupRouter(app *bootstrap.Application) *gin.Engine {
Expand Down

0 comments on commit c37666a

Please sign in to comment.