2015-05-13 02:35:16 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-05-13 16:44:44 +02:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2015-05-13 02:35:16 +02:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2015-05-13 20:54:54 +02:00
|
|
|
ConfigRuntime()
|
|
|
|
StartWorkers()
|
|
|
|
StartGin()
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConfigRuntime() {
|
2015-05-13 16:44:44 +02:00
|
|
|
nuCPU := runtime.NumCPU()
|
|
|
|
runtime.GOMAXPROCS(nuCPU)
|
|
|
|
fmt.Printf("Running with %d CPUs\n", nuCPU)
|
2015-05-13 20:54:54 +02:00
|
|
|
}
|
2015-05-13 16:44:44 +02:00
|
|
|
|
2015-05-13 20:54:54 +02:00
|
|
|
func StartWorkers() {
|
|
|
|
go statsWorker()
|
|
|
|
}
|
2015-05-13 16:44:44 +02:00
|
|
|
|
2015-05-13 20:54:54 +02:00
|
|
|
func StartGin() {
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
2015-05-13 03:19:44 +02:00
|
|
|
|
2015-05-14 20:25:55 +02:00
|
|
|
router := gin.New()
|
2015-05-14 20:43:33 +02:00
|
|
|
router.Use(rateLimit, gin.Recovery())
|
2015-05-13 02:35:16 +02:00
|
|
|
router.LoadHTMLGlob("resources/*.templ.html")
|
|
|
|
router.Static("/static", "resources/static")
|
|
|
|
router.GET("/", index)
|
|
|
|
router.GET("/room/:roomid", roomGET)
|
2015-05-13 17:34:42 +02:00
|
|
|
router.POST("/room-post/:roomid", roomPOST)
|
2015-05-13 02:35:16 +02:00
|
|
|
router.GET("/stream/:roomid", streamRoom)
|
|
|
|
|
2015-05-14 04:43:39 +02:00
|
|
|
router.Run(":80")
|
2015-05-13 02:35:16 +02:00
|
|
|
}
|