| 123456789101112131415161718192021222324252627282930313233 |
- package handler
- import (
- "net/http"
- "slowwildws/internal/logic"
- "slowwildws/internal/svc"
- "github.com/gorilla/websocket"
- xhttp "github.com/zeromicro/x/http"
- )
- func SlowwildwsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- var responseHeader http.Header
- if protocol := r.Header.Get("Sec-Websocket-Protocol"); protocol != "" {
- responseHeader = http.Header{
- "Sec-Websocket-Protocol": []string{protocol},
- }
- }
- upgrade := websocket.Upgrader{}
- conn, err := upgrade.Upgrade(w, r, responseHeader)
- if err != nil {
- xhttp.JsonBaseResponseCtx(r.Context(), w, err)
- return
- }
- l := logic.NewConnectionLogic(r.Context(), svcCtx, conn)
- go l.Keepalive()
- }
- }
|