Initial commit

This commit is contained in:
Henri Burau
2024-06-03 18:07:27 +02:00
commit ca04cc51f3
43 changed files with 4440 additions and 0 deletions

51
main.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"fmt"
"log"
"log/slog"
"net/http"
"os"
"time"
"gitea.henriburau.de/haw-lan/cod4watcher/models"
"gitea.henriburau.de/haw-lan/cod4watcher/routes"
"github.com/go-chi/chi"
"github.com/joho/godotenv"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal(err)
}
cod4server, err := models.NewCOD4ServerStatus("80.57.28.137", "28960", 1*time.Second)
if err != nil {
log.Panic(err)
}
status, err := cod4server.GetServerStatus()
if err != nil {
log.Panic(err)
}
log.Printf("%+v", status)
router := chi.NewMux()
server := &routes.Server{}
router.Handle("/*", public())
router.Get("/health", routes.Make(server.HandleHealth))
router.Get("/captures/{captureID}", routes.Make(server.HandleCapture))
router.Get("/", routes.Make(server.HandleHome))
listenAddr := os.Getenv("LISTEN_ADDR")
slog.Info("HTTP server started", "listenAddr", listenAddr)
http.ListenAndServe(listenAddr, router)
}
func public() http.Handler {
fmt.Println("building static files for development")
return http.StripPrefix("/assets/", http.FileServerFS(os.DirFS("assets")))
}