From 8fd834df742c26953f8fd56694d7583c11b5941b Mon Sep 17 00:00:00 2001 From: vsclub <1217179982@qq.com> Date: Tue, 27 Jan 2026 16:27:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=9A=E7=94=A8list=20to=20tree=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=BC=BA=E5=8C=96=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E9=A1=B6=E7=BA=A7=E8=8A=82=E7=82=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- net/http/session/storage/carrier_rdbms/rdbms.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/http/session/storage/carrier_rdbms/rdbms.go b/net/http/session/storage/carrier_rdbms/rdbms.go index de7f461..fc0adbd 100644 --- a/net/http/session/storage/carrier_rdbms/rdbms.go +++ b/net/http/session/storage/carrier_rdbms/rdbms.go @@ -19,7 +19,7 @@ func New(db *gorm.DB) *Instance { ins := &Instance{ db: db.Session(&gorm.Session{}), } - userDb.AutoCreateTableWithStruct(ins.db, session.Session{}, "创建session表失败") + userDb.AutoCreateTableWithStruct(ins.db, session.Session{}, "创建 session 表失败") return ins } From 9b13d97c11bc9123787af0a2e19f5a21b073075f Mon Sep 17 00:00:00 2001 From: vsclub <1217179982@qq.com> Date: Tue, 27 Jan 2026 18:29:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=92=88=E5=AF=B9=20http=20server=20?= =?UTF-8?q?=E7=9A=84addAny,=E5=B0=86=E7=9B=B4=E6=8E=A5=E7=BB=86=E5=8C=96?= =?UTF-8?q?=E6=9C=AA=E6=AF=8F=E7=A7=8Dmethod=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- net/http/httpServer/f_group.go | 2 +- net/http/server/group.go | 15 +++++++++++---- net/http/server/types.go | 12 ++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/net/http/httpServer/f_group.go b/net/http/httpServer/f_group.go index 5c10726..7ee919a 100644 --- a/net/http/httpServer/f_group.go +++ b/net/http/httpServer/f_group.go @@ -51,7 +51,7 @@ func (g *RouterGroup) addRoute(method, p string, handler http.Handler) { // Ws 添加 WebSocket 支持 func (g *RouterGroup) Ws(p string, handler func(ws *websocket.Conn)) { fullPath := g.calculatePrefix(p) - g.service.addWSRoute(fullPath, handler) + g.service.addWSRoute("GET "+fullPath, handler) } // Use 支持链式调用 diff --git a/net/http/server/group.go b/net/http/server/group.go index 438629c..a494e4f 100644 --- a/net/http/server/group.go +++ b/net/http/server/group.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "net/http" "strings" @@ -132,19 +133,25 @@ func (g *Group[T]) TraceWithHandler(p string, handler http.Handler, descriptions } func (g *Group[T]) Any(p string, handler http.HandlerFunc, descriptions ...Description[T]) { - g.addRoute("", p, handler, descriptions...) + for _, method := range HttpMethodList { + g.addRoute(method, p, handler, descriptions...) + } } func (g *Group[T]) AnyWithHandler(p string, handler http.Handler, descriptions ...Description[T]) { - g.addRoute("", p, handler, descriptions...) + for _, method := range HttpMethodList { + g.addRoute(method, p, handler, descriptions...) + } } +// WS 对于WS类型,由于新版本的http server,不支持混合路由。 +// 所以指定成GET func (g *Group[T]) WS(p string, handler func(ws *websocket.Conn)) { fullPath := g.calculatePrefix(strings.TrimSpace(p)) - g.serv.AddWebsocketRoute(fullPath, handler) + g.serv.AddWebsocketRoute(fmt.Sprintf("%s %s", http.MethodGet, fullPath), handler) } func (g *Group[T]) WSWithDescription(p string, handler func(ws *websocket.Conn), description Description[T]) { fullPath := g.calculatePrefix(strings.TrimSpace(p)) - g.serv.AddWebsocketRouteWithDescription(fullPath, handler, description) + g.serv.AddWebsocketRouteWithDescription(fmt.Sprintf("%s %s", http.MethodGet, fullPath), handler, description) } diff --git a/net/http/server/types.go b/net/http/server/types.go index 589c465..6ce1601 100644 --- a/net/http/server/types.go +++ b/net/http/server/types.go @@ -105,3 +105,15 @@ func NewDesc[T any](key, code string, meta *T) Description[T] { Metadata: meta, } } + +var HttpMethodList = []string{ + http.MethodGet, + http.MethodHead, + http.MethodPost, + http.MethodPut, + http.MethodPatch, + http.MethodDelete, + http.MethodConnect, + http.MethodOptions, + http.MethodTrace, +}