Files
golias/main.go
2025-05-08 10:25:38 +03:00

43 lines
1.2 KiB
Go

package main
import (
"golias/handlers"
"log/slog"
"net/http"
"time"
)
// TODO: add config as param
func ListenToRequests(port string) error {
mux := http.NewServeMux()
server := &http.Server{
Handler: handlers.LogRequests(handlers.GetSession(mux)),
Addr: port,
ReadTimeout: time.Second * 5,
WriteTimeout: time.Second * 5,
}
fs := http.FileServer(http.Dir("assets/"))
mux.Handle("GET /assets/", http.StripPrefix("/assets/", fs))
//
mux.HandleFunc("GET /ping", handlers.HandlePing)
mux.HandleFunc("GET /", handlers.HandleHome)
mux.HandleFunc("POST /login", handlers.HandleFrontLogin)
mux.HandleFunc("GET /room", handlers.HandleRoomEnter)
mux.HandleFunc("GET /join-team", handlers.HandleJoinTeam)
//elements
mux.HandleFunc("GET /room/createform", handlers.HandleShowCreateForm)
mux.HandleFunc("GET /room/hideform", handlers.HandleHideCreateForm)
mux.HandleFunc("GET /word/show-color", handlers.HandleShowColor)
mux.HandleFunc("POST /check/name", handlers.HandleNameCheck)
slog.Info("Listening", "addr", port)
return server.ListenAndServe()
}
func main() {
port := ":3000"
err := ListenToRequests(port)
if err != nil {
panic(err)
}
}