mirror of https://github.com/gin-gonic/gin.git
43 lines
842 B
Go
43 lines
842 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func main() {
|
|
ConfigRuntime()
|
|
StartWorkers()
|
|
StartGin()
|
|
}
|
|
|
|
// ConfigRuntime sets the number of operating system threads.
|
|
func ConfigRuntime() {
|
|
nuCPU := runtime.NumCPU()
|
|
runtime.GOMAXPROCS(nuCPU)
|
|
fmt.Printf("Running with %d CPUs\n", nuCPU)
|
|
}
|
|
|
|
// StartWorkers start starsWorker by goroutine.
|
|
func StartWorkers() {
|
|
go statsWorker()
|
|
}
|
|
|
|
// StartGin starts gin web server with setting router.
|
|
func StartGin() {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
router := gin.New()
|
|
router.Use(rateLimit, gin.Recovery())
|
|
router.LoadHTMLGlob("resources/*.templ.html")
|
|
router.Static("/static", "resources/static")
|
|
router.GET("/", index)
|
|
router.GET("/room/:roomid", roomGET)
|
|
router.POST("/room-post/:roomid", roomPOST)
|
|
router.GET("/stream/:roomid", streamRoom)
|
|
|
|
router.Run(":80")
|
|
}
|