All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m19s
31 lines
519 B
Go
31 lines
519 B
Go
package controllers
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"server/models"
|
|
"sync"
|
|
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
type Hub struct {
|
|
Entities map[uint32]models.Entity
|
|
Clients map[uint32]*websocket.Conn
|
|
Mu sync.RWMutex
|
|
}
|
|
|
|
func NewHub() *Hub {
|
|
return &Hub{
|
|
Entities: make(map[uint32]models.Entity),
|
|
Clients: make(map[uint32]*websocket.Conn),
|
|
}
|
|
}
|
|
|
|
func (h *Hub) Start() {
|
|
go h.updateWorld()
|
|
http.HandleFunc("/ws", h.ws)
|
|
log.Println("Server listen port 8080")
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
}
|