refactor(app): moved all db and log to one intialize spot

This commit is contained in:
2025-08-04 06:54:21 -05:00
parent 486e4fb6b8
commit 0ecbe29ec1
13 changed files with 148 additions and 99 deletions

View File

@@ -13,6 +13,7 @@ import (
)
func main() {
log := logger.New()
if os.Getenv("RUNNING_IN_DOCKER") != "true" {
err := godotenv.Load("../.env")
if err != nil {
@@ -23,7 +24,7 @@ func main() {
// Initialize DB
if _, err := db.InitDB(); err != nil {
log := logger.New()
log.Panic("Database intialize failed", "db", map[string]interface{}{
"error": err.Error(),
"casue": errors.Unwrap(err),
@@ -33,7 +34,7 @@ func main() {
}
defer func() {
if r := recover(); r != nil {
log := logger.New()
sqlDB, _ := db.DB.DB()
sqlDB.Close()
log.Error("Recovered from panic during DB shutdown", "db", map[string]interface{}{
@@ -56,7 +57,7 @@ func main() {
fmt.Println("Welcome to lst backend where all the fun happens.")
// Init Gin router and pass DB to services
r := router.Setup(db.DB, basePath)
r := router.Setup(db.DB, basePath, log)
// get the server port
port := "8080"