作者 yangfu

ws

package websocket
import (
"github.com/gorilla/websocket"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
ws "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"net/http"
"strconv"
)
var upgrader = websocket.Upgrader{}
func Upgrage(w http.ResponseWriter, r *http.Request) {
requestHead := &mybeego.RequestHead{}
requestHead.Uid, _ = strconv.ParseInt(r.Header.Get("uid"), 10, 64)
requestHead.AppId, _ = strconv.Atoi(r.Header.Get("appid"))
requestHead.Token = r.Header.Get("token")
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Fatal(err)
}
wsConn := ws.NewWebsocketConnection(conn, requestHead, WsOnReceive)
wsConn.Serve()
}
func WsOnReceive(data []byte) *mybeego.Message {
return mybeego.NewMessage(0)
}
\ No newline at end of file
... ...