完善资源关闭逻辑,添加数据库和Redis连接的退出处理

This commit is contained in:
2025-04-01 11:26:37 +08:00
parent 6d89470a89
commit 87eecdb8cb
7 changed files with 74 additions and 50 deletions

View File

@@ -10,6 +10,8 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/requestid"
"github.com/google/uuid"
"github.com/jxskiss/base62"
)
import _ "net/http/pprof"
@@ -36,6 +38,7 @@ func New(config *Config) (*Server, error) {
func (s *Server) Run() error {
// config
s.fiber = fiber.New(fiber.Config{
ErrorHandler: ErrorHandler,
})
@@ -43,7 +46,12 @@ func (s *Server) Run() error {
s.fiber.Use(logger.New(logger.Config{
DisableColors: false,
}))
s.fiber.Use(requestid.New())
s.fiber.Use(requestid.New(requestid.Config{
Generator: func() string {
binary, _ := uuid.New().MarshalBinary()
return base62.EncodeToString(binary)
},
}))
ApplyRouters(s.fiber)
@@ -56,6 +64,7 @@ func (s *Server) Run() error {
}
}()
// listen
port := env.AppPort
slog.Info("Server started on :" + port)
err := s.fiber.Listen(":" + port)