Closed wbbbbbbbbbbbbbbbbbb closed 1 year ago
贴段代码看看
随便写了个demo, 没发现有问题
var upgrader = gws.NewUpgrader(&Handler{}, nil)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/connect",
Handler: WsHandler(serverCtx),
},
},
)
}
func WsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r)
if err != nil {
log.Println(err.Error())
return
}
conn.ReadLoop()
}
}
type Handler struct {
gws.BuiltinEventHandler
}
sry。。是我的问题,我设置过期时间的时候忘记 * time.Second 导致关闭的过快了。
我在gozero项目中接入gws,按照chatroom的例子来写的时候,报错以下错误: error write response failed, error: http: connection has been hijacked caller=httpx/responses.go:81