update
This commit is contained in:
33
main.go
33
main.go
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user