您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

35 行
778B

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/gorilla/websocket"
  5. log "github.com/sirupsen/logrus"
  6. )
  7. type apiV1WsHandlerMap struct {
  8. Keyword string // keyword
  9. Handler func(conn *websocket.Conn, msg map[string]string)
  10. }
  11. var apiV1WsHandler = []apiV1WsHandlerMap{
  12. {"echo", apiV1WsEcho},
  13. {"register-session", apiV1WsRegisterSession},
  14. }
  15. func apiV1WsEcho(conn *websocket.Conn, msg map[string]string) {
  16. // print out that message for clarity
  17. fmt.Println(msg)
  18. // this is echo
  19. if err := conn.WriteMessage(websocket.TextMessage, []byte(msg["t"])); err != nil {
  20. wsq.del(conn)
  21. log.Println(err)
  22. }
  23. }
  24. func apiV1WsRegisterSession(conn *websocket.Conn, msg map[string]string) {
  25. sid := msg["session"]
  26. wsq.MapSessionToConnection(sid, conn)
  27. log.Info("ws register session:", sid)
  28. }