2015-05-13 00:35:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-05-13 14:44:44 +00:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2015-05-13 00:35:16 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2015-05-13 18:54:54 +00:00
|
|
|
ConfigRuntime()
|
|
|
|
StartWorkers()
|
|
|
|
StartGin()
|
|
|
|
}
|
|
|
|
|
2018-09-15 02:23:32 +00:00
|
|
|
// ConfigRuntime sets the number of operating system threads.
|
2015-05-13 18:54:54 +00:00
|
|
|
func ConfigRuntime() {
|
2015-05-13 14:44:44 +00:00
|
|
|
nuCPU := runtime.NumCPU()
|
|
|
|
runtime.GOMAXPROCS(nuCPU)
|
|
|
|
fmt.Printf("Running with %d CPUs\n", nuCPU)
|
2015-05-13 18:54:54 +00:00
|
|
|
}
|
2015-05-13 14:44:44 +00:00
|
|
|
|
2018-09-15 07:21:54 +00:00
|
|
|
// StartWorkers start starsWorker by goroutine.
|
2015-05-13 18:54:54 +00:00
|
|
|
func StartWorkers() {
|
|
|
|
go statsWorker()
|
|
|
|
}
|
2015-05-13 14:44:44 +00:00
|
|
|
|
2018-09-15 02:23:32 +00:00
|
|
|
// StartGin starts gin web server with setting router.
|
2015-05-13 18:54:54 +00:00
|
|
|
func StartGin() {
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
2015-05-13 01:19:44 +00:00
|
|
|
|
2015-05-14 18:25:55 +00:00
|
|
|
router := gin.New()
|
2015-05-14 18:43:33 +00:00
|
|
|
router.Use(rateLimit, gin.Recovery())
|
2015-05-13 00:35:16 +00:00
|
|
|
router.LoadHTMLGlob("resources/*.templ.html")
|
|
|
|
router.Static("/static", "resources/static")
|
|
|
|
router.GET("/", index)
|
|
|
|
router.GET("/room/:roomid", roomGET)
|
2015-05-13 15:34:42 +00:00
|
|
|
router.POST("/room-post/:roomid", roomPOST)
|
2015-05-13 00:35:16 +00:00
|
|
|
router.GET("/stream/:roomid", streamRoom)
|
|
|
|
|
2015-05-14 02:43:39 +00:00
|
|
|
router.Run(":80")
|
2015-05-13 00:35:16 +00:00
|
|
|
}
|