修复(#104): 修复 goctl 重新生成代码漂移
Build docker and publish / build (20.15.1) (push) Failing after 58s
Build docker and publish / build (20.15.1) (pull_request) Failing after 52s

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
2026-05-27 23:54:26 -07:00
parent 197fed7d12
commit fefbd4f56a
43 changed files with 3001 additions and 1513 deletions
+5
View File
@@ -0,0 +1,5 @@
module github.com/zeromicro/go-zero
go 1.24
require github.com/gin-gonic/gin v1.10.0
+109
View File
@@ -0,0 +1,109 @@
package rest
import (
"net/http"
"path"
"strings"
"github.com/gin-gonic/gin"
)
type Middleware = gin.HandlerFunc
type Route struct {
Method string
Path string
Handler gin.HandlerFunc
}
type Server struct {
router *gin.Engine
}
type routeOptions struct {
prefix string
middleware []Middleware
}
type RouteOption func(*routeOptions)
func NewGinServer(router *gin.Engine) *Server {
return &Server{router: router}
}
func WithMiddlewares(middlewares []Middleware, routes ...Route) []Route {
for i := range routes {
routes[i].Handler = chain(middlewares, routes[i].Handler)
}
return routes
}
func WithPrefix(prefix string) RouteOption {
return func(options *routeOptions) {
options.prefix = prefix
}
}
func WithJwt(_ string) RouteOption {
return func(*routeOptions) {}
}
func WithJwtTransition(_, _ string) RouteOption {
return func(*routeOptions) {}
}
func WithSignature(_ any) RouteOption {
return func(*routeOptions) {}
}
func WithSSE() RouteOption {
return func(*routeOptions) {}
}
func WithMaxBytes(_ int64) RouteOption {
return func(*routeOptions) {}
}
func WithTimeout(_ any) RouteOption {
return func(*routeOptions) {}
}
func (s *Server) AddRoutes(routes []Route, opts ...RouteOption) {
options := routeOptions{}
for _, opt := range opts {
opt(&options)
}
for _, route := range routes {
s.router.Handle(route.Method, joinPath(options.prefix, route.Path), chain(options.middleware, route.Handler))
}
}
func chain(middlewares []Middleware, handler gin.HandlerFunc) gin.HandlerFunc {
if len(middlewares) == 0 {
return handler
}
return func(c *gin.Context) {
for _, middleware := range middlewares {
middleware(c)
if c.IsAborted() {
return
}
}
handler(c)
}
}
func joinPath(prefix, routePath string) string {
if prefix == "" {
return routePath
}
joined := path.Join("/", prefix, routePath)
if strings.HasSuffix(routePath, "/") && !strings.HasSuffix(joined, "/") {
joined += "/"
}
return joined
}
var (
_ http.Handler
)