This commit is contained in:
laodaming
2023-07-26 16:00:19 +08:00
parent 36aad6a088
commit 88a59bbdea
5 changed files with 46 additions and 1 deletions

View File

@@ -1,12 +1,14 @@
package logic
import (
"bytes"
"encoding/json"
"fmt"
"fusenapi/constants"
"fusenapi/server/websocket/internal/types"
"github.com/google/uuid"
"github.com/gorilla/websocket"
"github.com/zeromicro/go-zero/rest/httpx"
"net/http"
"sync"
"time"
@@ -32,12 +34,24 @@ func NewDataTransferLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Data
}
var (
//升级
buffPool = sync.Pool{
New: func() interface{} {
return bytes.Buffer{}
},
}
//升级websocket
upgrade = websocket.Upgrader{
//握手超时时间15s
HandshakeTimeout: time.Second * 15,
//允许跨域
CheckOrigin: func(r *http.Request) bool {
return true
},
Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
httpx.ErrorCtx(r.Context(), w, reason)
return
},
WriteBufferPool: &buffPool,
}
//连接map池
mapConnPool = sync.Map{}