[feat] 重新梳理 ws
This commit is contained in:
parent
6d3b2267b9
commit
584571513c
41
http.go
41
http.go
@ -40,28 +40,11 @@ type HttpController interface {
|
|||||||
AuthDB() req.ResAuthDB
|
AuthDB() req.ResAuthDB
|
||||||
}
|
}
|
||||||
|
|
||||||
type WsController interface {
|
|
||||||
HttpController
|
|
||||||
// 请求处理
|
|
||||||
ExecuteWS(req.GlobalParams) error
|
|
||||||
// 获取 Ws 客户端
|
|
||||||
WsClient() WsClient
|
|
||||||
// 获取 Ws 标识
|
|
||||||
WsClientId(req.GlobalParams) WsClientID
|
|
||||||
// 获取 Ws 分组
|
|
||||||
WsClientGroup(req.GlobalParams) WsClientGroup
|
|
||||||
}
|
|
||||||
|
|
||||||
type HttpHandleController struct {
|
type HttpHandleController struct {
|
||||||
Controller
|
Controller
|
||||||
request *http.Request
|
request *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
type WsHandleController struct {
|
|
||||||
HttpController
|
|
||||||
ws WsClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this HttpHandleController) Request() *http.Request {
|
func (this HttpHandleController) Request() *http.Request {
|
||||||
return this.request
|
return this.request
|
||||||
}
|
}
|
||||||
@ -86,33 +69,9 @@ func (HttpHandleController) AuthDB() req.ResAuthDB {
|
|||||||
return req.ResAuthOn
|
return req.ResAuthOn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (WsHandleController) ExecuteWS(params req.GlobalParams) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this WsHandleController) WsClient() WsClient {
|
|
||||||
return this.ws
|
|
||||||
}
|
|
||||||
|
|
||||||
func (WsHandleController) WsClientId(req.GlobalParams) WsClientID {
|
|
||||||
wsClientID++
|
|
||||||
return wsClientID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (WsHandleController) WsClientGroup(req.GlobalParams) WsClientGroup {
|
|
||||||
return defaultWsClientGroup
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHttpController(container *do.Injector, request *http.Request) HttpController {
|
func NewHttpController(container *do.Injector, request *http.Request) HttpController {
|
||||||
return &HttpHandleController{
|
return &HttpHandleController{
|
||||||
Controller: &BaseController{container},
|
Controller: &BaseController{container},
|
||||||
request: request,
|
request: request,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWsController(ws WsClient, ctr HttpController) WsController {
|
|
||||||
return &WsHandleController{
|
|
||||||
HttpController: ctr,
|
|
||||||
ws: ws,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
63
ws.go
63
ws.go
@ -1,8 +1,11 @@
|
|||||||
package contracts
|
package contracts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"git.fsdpf.net/go/req"
|
"git.fsdpf.net/go/req"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/samber/do"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WsClientGroup string
|
type WsClientGroup string
|
||||||
@ -33,3 +36,63 @@ type WsClientManage interface {
|
|||||||
type WsChannelManage interface {
|
type WsChannelManage interface {
|
||||||
Channel(string) WsClientManage
|
Channel(string) WsClientManage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WsController interface {
|
||||||
|
// 获取请求信息
|
||||||
|
Request() *http.Request
|
||||||
|
// 请求处理
|
||||||
|
Execute(req.GlobalParams) error
|
||||||
|
// 获取用户信息
|
||||||
|
User() req.User
|
||||||
|
// 路由信息
|
||||||
|
Route() req.Route
|
||||||
|
// 获取 Ws 客户端
|
||||||
|
Client() WsClient
|
||||||
|
// 获取 Ws 标识
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user