package websocket import ( "net/http" "github.com/gin-gonic/gin" ws "github.com/gorilla/websocket" ) var upgrader = ws.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, } func Conn(ctx *gin.Context) (*ws.Conn, error) { upgrader.Subprotocols = []string{ctx.GetHeader("Sec-WebSocket-Protocol")} return upgrader.Upgrade(ctx.Writer, ctx.Request, nil) }