Browse Source

[🚀] ws 添加兼容HandlerFunc

bvbej 1 year ago
parent
commit
6fb3350bae
1 changed files with 8 additions and 0 deletions
  1. 8 0
      pkg/websocket/peer/connect/acceptor.go

+ 8 - 0
pkg/websocket/peer/connect/acceptor.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"git.bvbej.com/bvbej/base-golang/pkg/mux"
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
 	"net/http"
@@ -26,6 +27,7 @@ type WsAcceptor interface {
 	Start(addr string) error
 	Stop()
 	GinHandle(ctx *gin.Context)
+	HandlerFunc() mux.HandlerFunc
 }
 
 type wsAcceptor struct {
@@ -88,3 +90,9 @@ func (ws *wsAcceptor) GinHandle(ctx *gin.Context) {
 	}
 	ws.sessMgr.Register <- peer.NewSession(NewConnection(c, ws.sessMgr))
 }
+
+func (ws *wsAcceptor) HandlerFunc() mux.HandlerFunc {
+	return func(c mux.Context) {
+		ws.GinHandle(c.Context())
+	}
+}