2 Star 11 Fork 12

联犀/中台模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
websocket.go 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2025-03-08 22:24 +08:00 . fix: 修复websocket订阅可能只发其中一个
package websocket
import (
"github.com/zeromicro/go-zero/rest"
"time"
)
type WsType string
const (
Sub WsType = "up.sub" //订阅
SubRet WsType = "down.subRet" //订阅回复
Pub WsType = "down.pub" //发布
Control WsType = "up.control" //控制
ControlRet WsType = "down.controlRet" //控制回复
UnSub WsType = "up.unSub" //取消订阅
UnSubRet WsType = "down.unSubRet" //取消订阅回复
SetHandle WsType = "up.setHandle" //设置http头
UpPing WsType = "up.ping" //测试ws连接,发啥返回啥
DownPong WsType = "down.pong" //测试ws连接,发啥返回啥
)
type SubscribeInfo struct {
Code string `json:"code"`
Params map[string]any `json:"params"`
}
type (
WsBody struct {
Handler map[string]string `json:"handler,omitempty"`
Type WsType `json:"type,omitempty"` //req 请求类型
Path string `json:"path,omitempty"` //url路径或发布及订阅的主题
Body any `json:"body,omitempty"` //消息体
}
WsReq struct {
// Method specifies the HTTP method (GET, POST, PUT, etc.).
// For client requests, an empty string means GET.
//
// Go's HTTP client does not support sending a request with
// the CONNECT method. See the documentation on Transport for
// details.
Method string `json:"method"`
WsBody
}
WsResp struct {
Code int64 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
WsBody
}
Ping struct {
Ping int64 `json:"ping"` //时间戳
}
Pong struct {
Pong int64 `json:"pong"` //时间戳
}
)
type (
jwtSetting struct {
enabled bool
secret string
prevSecret string
}
RouteOption func(r *featuredRoutes)
signatureSetting struct {
rest.SignatureConf
enabled bool
}
featuredRoutes struct {
timeout time.Duration
priority bool
jwt jwtSetting
signature signatureSetting
routes []rest.Route
maxBytes int64
}
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/core.git
git@gitee.com:unitedrhino/core.git
unitedrhino
core
中台模块
v1.5.0

搜索帮助