Base Project
This commit is contained in:
45
global/global.go
Normal file
45
global/global.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"wm-backend/configs"
|
||||
"wm-backend/internal/initialization"
|
||||
"wm-backend/internal/models"
|
||||
db "wm-backend/sqlc_gen"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
Cfg models.Config
|
||||
DB *pgxpool.Pool
|
||||
Queries *db.Queries
|
||||
Cache *redis.Client
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
// Load Configurations
|
||||
Cfg, err = configs.LoadConfig("configs")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Error loading config")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// DATABASE
|
||||
DB, err = initialization.ConnectPostgreSQL(&Cfg)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Error connecting to database")
|
||||
panic(err)
|
||||
}
|
||||
Queries = db.New(DB)
|
||||
|
||||
// CACHE
|
||||
Cache, err = initialization.ConnectRedis(Cfg)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Error connecting to Redis")
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user