main.go 677 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "fmt"
  4. "runtime"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func main() {
  8. ConfigRuntime()
  9. StartWorkers()
  10. StartGin()
  11. }
  12. func ConfigRuntime() {
  13. nuCPU := runtime.NumCPU()
  14. runtime.GOMAXPROCS(nuCPU)
  15. fmt.Printf("Running with %d CPUs\n", nuCPU)
  16. }
  17. func StartWorkers() {
  18. go statsWorker()
  19. }
  20. func StartGin() {
  21. gin.SetMode(gin.ReleaseMode)
  22. router := gin.New()
  23. router.Use(rateLimit, gin.Recovery())
  24. router.LoadHTMLGlob("resources/*.templ.html")
  25. router.Static("/static", "resources/static")
  26. router.GET("/", index)
  27. router.GET("/room/:roomid", roomGET)
  28. router.POST("/room-post/:roomid", roomPOST)
  29. router.GET("/stream/:roomid", streamRoom)
  30. router.Run(":80")
  31. }