main.go 842 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // ConfigRuntime sets the number of operating system threads.
  13. func ConfigRuntime() {
  14. nuCPU := runtime.NumCPU()
  15. runtime.GOMAXPROCS(nuCPU)
  16. fmt.Printf("Running with %d CPUs\n", nuCPU)
  17. }
  18. // StartWorkers start starsWorker by goroutine.
  19. func StartWorkers() {
  20. go statsWorker()
  21. }
  22. // StartGin starts gin web server with setting router.
  23. func StartGin() {
  24. gin.SetMode(gin.ReleaseMode)
  25. router := gin.New()
  26. router.Use(rateLimit, gin.Recovery())
  27. router.LoadHTMLGlob("resources/*.templ.html")
  28. router.Static("/static", "resources/static")
  29. router.GET("/", index)
  30. router.GET("/room/:roomid", roomGET)
  31. router.POST("/room-post/:roomid", roomPOST)
  32. router.GET("/stream/:roomid", streamRoom)
  33. router.Run(":80")
  34. }