forked from render-examples/go-gin-web-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (41 loc) · 969 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"runtime"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/recover"
)
func main() {
ConfigRuntime()
StartWorkers()
StartIris()
}
// 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()
}
// StartIris starts Iris web server with setting router.
func StartIris() {
app := iris.New()
app.Use(recover.New(), rateLimit)
app.RegisterView(iris.HTML("./resources", ".html"))
app.HandleDir("/static", "resources/static", iris.DirOptions{
Compress: true,
})
app.Get("/", index)
app.Get("/room/{roomid}", roomGET)
app.Post("/room-post/{roomid}", roomPOST)
app.Get("/events", listenEvents())
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
app.Listen(":" + port)
}