This commit is contained in:
Cereska
2026-03-02 08:47:52 -05:00
parent a1b599d030
commit 661011485c
7 changed files with 184 additions and 42 deletions

33
main.go
View File

@@ -1 +1,34 @@
package main
import (
"chat/internal/cache"
"chat/internal/models"
"chat/internal/web"
"net/http"
"time"
"github.com/coder/websocket"
)
func main() {
// Initialize cache
cache := cache.NewCache(10 * time.Minute)
// Pregenerate "General" chat room
generalRoom := &models.Channel{
ID: "general",
RoomName: "General Chat",
Clients: make(map[*websocket.Conn]bool),
}
cache.Set(generalRoom.ID, generalRoom, 24*time.Hour)
// Define websocket route
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
web.HandleChat(w, r, cache)
})
// Serve frontend
http.Handle("/", http.FileServer(http.Dir(".")))
http.ListenAndServe(":8080", nil)
}