Files
tma-back/controllers/hub.go
Smile Rex 3c989c33f8
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m19s
new server
2026-01-17 16:38:45 +03:00

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))
}