重构: 各类型 Controller 接口精简,配合 framework-v2 internal/handler 收拢公共实现
app.go/condflow.go/cron.go/event_stream.go/executor.go/gobridge.go/grpc.go/job.go/mcp.go/mqtt.go/res_virtual_table.go/ws.go/controller.go/support/service.go 精简掉搬到 framework-v2 internal/handler 里的公共默认实现,只保留接口定义。
This commit is contained in:
@@ -5,17 +5,12 @@ import (
|
||||
|
||||
"git.fsdpf.net/go/req"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/samber/do/v2"
|
||||
)
|
||||
|
||||
type WsClientGroup string
|
||||
type WsClientID uint
|
||||
|
||||
// type WsClient struct {
|
||||
// User
|
||||
// Group WsClientGroup
|
||||
// Socket *websocket.Conn
|
||||
// }
|
||||
const DefaultWsClientGroup WsClientGroup = "__DEFAULT__"
|
||||
|
||||
type WsClient interface {
|
||||
req.User
|
||||
@@ -50,50 +45,7 @@ type WsController interface {
|
||||
// 获取 Ws 客户端
|
||||
Client() WsClient
|
||||
// 获取 Ws 标识
|
||||
ClientId(req.GlobalParams) WsClientID
|
||||
ClientID(req.GlobalParams) WsClientID
|
||||
// 获取 Ws 分组
|
||||
ClientGroup(req.GlobalParams) WsClientGroup
|
||||
}
|
||||
|
||||
type WsHandleController struct {
|
||||
Controller
|
||||
ws WsClient
|
||||
request *http.Request
|
||||
}
|
||||
|
||||
func (this WsHandleController) Request() *http.Request {
|
||||
return this.request
|
||||
}
|
||||
|
||||
func (this WsHandleController) Route() req.Route {
|
||||
return this.Request().Context().Value(req.RouteCtx{Name: "Route"}).(req.Route)
|
||||
}
|
||||
|
||||
func (this WsHandleController) User() req.User {
|
||||
return this.Request().Context().Value(req.RouteCtx{Name: "User"}).(req.User)
|
||||
}
|
||||
|
||||
func (this WsHandleController) Execute(req.GlobalParams) error {
|
||||
return ErrFuncNotImplemented
|
||||
}
|
||||
|
||||
func (this WsHandleController) Client() WsClient {
|
||||
return this.ws
|
||||
}
|
||||
|
||||
func (WsHandleController) ClientId(req.GlobalParams) WsClientID {
|
||||
wsClientID++
|
||||
return wsClientID
|
||||
}
|
||||
|
||||
func (WsHandleController) ClientGroup(req.GlobalParams) WsClientGroup {
|
||||
return defaultWsClientGroup
|
||||
}
|
||||
|
||||
func NewWsController(container do.Injector, request *http.Request, ws WsClient) WsController {
|
||||
return &WsHandleController{
|
||||
Controller: &BaseController{container},
|
||||
request: request,
|
||||
ws: ws,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user