main.go 714 B

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