chores: refactor struct and structure project
This commit is contained in:
+12
-1
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
@@ -32,16 +33,26 @@ func init() {
|
||||
config.InitEnv()
|
||||
}
|
||||
|
||||
func run(lc fx.Lifecycle, db *database.DB, apiRouter chi.Router) {
|
||||
func run(
|
||||
lc fx.Lifecycle,
|
||||
db *database.DB,
|
||||
apiRouter chi.Router,
|
||||
rdb *redis.Client,
|
||||
) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
fmt.Println("Application has started...")
|
||||
_, err := rdb.Ping(ctx).Result()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not connect to Redis: %v", err)
|
||||
}
|
||||
pkgconfig.Router(apiRouter)
|
||||
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
fmt.Println("Shutting down...")
|
||||
rdb.Close()
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user