Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net/http/httpServer/f_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 支持链式调用
Expand Down
15 changes: 11 additions & 4 deletions net/http/server/group.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -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)
}
12 changes: 12 additions & 0 deletions net/http/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion net/http/session/storage/carrier_rdbms/rdbms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down