feat(socket): 实现 WebSocket 代理功能

- 新增 WebSocket 中间件,支持连接到指定端口的 TCP 服务器
- 在 ServerEvent 中添加错误日志输出
- 优化 ClientData 解析逻辑,增加类型断言
- 更新 index.html,添加 socket 代理配置
This commit is contained in:
2025-07-10 01:01:43 +08:00
parent c76c2f4139
commit cd2a5db9d2
5 changed files with 111 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/util/gconv"
"github.com/lxzan/gws"
)
@@ -41,9 +42,13 @@ func init() {
if config.Config.Middleware.Log.Enable {
g.Server().BindMiddleware("/admin/*", BaseLog)
}
g.Server().BindHandler("/ws", func(r *ghttp.Request) {
g.Server().BindHandler("/ws/*", func(r *ghttp.Request) {
urls := r.URL.Query().Get("port")
fmt.Println(urls)
tt := new(Handler)
upgrader := gws.NewUpgrader(new(Handler), &gws.ServerOption{
tt.port = gconv.Int(urls)
upgrader := gws.NewUpgrader(tt, &gws.ServerOption{
//CompressEnabled: true,
// 在querystring里面传入用户名