优化结构
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -79,28 +78,9 @@ func NewGinEngineWithRuntime(runtime *conf.Runtime, access *service.AccessContro
|
||||
}
|
||||
httpx.Fail(c, "请求的接口不存在")
|
||||
})
|
||||
logRegisteredRoutes(engine, logger)
|
||||
return engine
|
||||
}
|
||||
|
||||
func logRegisteredRoutes(engine *gin.Engine, logger *slog.Logger) {
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
routes := append([]gin.RouteInfo(nil), engine.Routes()...)
|
||||
sort.Slice(routes, func(i, j int) bool {
|
||||
if routes[i].Path == routes[j].Path {
|
||||
return routes[i].Method < routes[j].Method
|
||||
}
|
||||
return routes[i].Path < routes[j].Path
|
||||
})
|
||||
systemLogger := logger.With("mod", "system")
|
||||
for _, route := range routes {
|
||||
systemLogger.Info("router registered", "method", route.Method, "path", route.Path)
|
||||
}
|
||||
systemLogger.Info("router register success", "route_count", len(routes))
|
||||
}
|
||||
|
||||
func NewGinServer(c *conf.Server, engine *gin.Engine) *kratoshttp.Server {
|
||||
network, address := "tcp", ":8000"
|
||||
if c != nil && c.Http != nil {
|
||||
|
||||
Reference in New Issue
Block a user