|
- package main
-
- import (
- "fmt"
- "github.com/gorilla/websocket"
- log "github.com/sirupsen/logrus"
- )
-
- type apiV1WsHandlerMap struct {
- Keyword string // keyword
- Handler func(conn *websocket.Conn, msg map[string]string)
- }
-
- var apiV1WsHandler = []apiV1WsHandlerMap{
- {"echo", apiV1WsEcho},
- {"register-session", apiV1WsRegisterSession},
- }
-
- func apiV1WsEcho(conn *websocket.Conn, msg map[string]string) {
- // print out that message for clarity
- fmt.Println(msg)
-
- // this is echo
- if err := conn.WriteMessage(websocket.TextMessage, []byte(msg["t"])); err != nil {
- wsq.del(conn)
- log.Println(err)
- }
- }
-
- func apiV1WsRegisterSession(conn *websocket.Conn, msg map[string]string) {
- sid := msg["session"]
- wsq.MapSessionToConnection(sid, conn)
- log.Info("ws register session:", sid)
- }
|