| 29 | } |
| 30 | |
| 31 | func NewHttpServer(httpServerAddr string, wsCommandFnRegistry map[string]WsCommandFn) (*HttpServer, error) { |
| 32 | wsHub := newWsHub(wsCommandFnRegistry) |
| 33 | |
| 34 | httpServer := &HttpServer{ |
| 35 | HttpServerAddr: httpServerAddr, |
| 36 | WsHub: wsHub, |
| 37 | } |
| 38 | http.HandleFunc("/", httpServer.serveHome) |
| 39 | http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { |
| 40 | httpServer.serveWs(w, r) |
| 41 | }) |
| 42 | |
| 43 | return httpServer, nil |
| 44 | } |
| 45 | |
| 46 | func (s *HttpServer) Run(waitGroup *sync.WaitGroup) { |
| 47 | defer waitGroup.Done() |