mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-11 02:43:44 +08:00
feat: implement centralized error response handling and add logger middleware
This commit is contained in:
16
main.go
16
main.go
@@ -7,6 +7,8 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
gmw "github.com/Laisky/gin-middlewares/v6"
|
||||
glog "github.com/Laisky/go-utils/v5/log"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -101,8 +103,20 @@ func main() {
|
||||
}
|
||||
|
||||
// Initialize HTTP server
|
||||
logLevel := glog.LevelInfo
|
||||
if config.DebugEnabled {
|
||||
logLevel = glog.LevelDebug
|
||||
}
|
||||
server := gin.New()
|
||||
server.Use(gin.Recovery())
|
||||
server.RedirectTrailingSlash = false
|
||||
server.Use(
|
||||
gin.Recovery(),
|
||||
gmw.NewLoggerMiddleware(
|
||||
gmw.WithLoggerMwColored(),
|
||||
gmw.WithLevel(logLevel.String()),
|
||||
gmw.WithLogger(glog.Shared.Named("one-api")),
|
||||
),
|
||||
)
|
||||
// This will cause SSE not to work!!!
|
||||
//server.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||
server.Use(middleware.RequestId())
|
||||
|
||||
Reference in New Issue
Block a user