/
route.go
48 lines (38 loc) · 836 Bytes
/
route.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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/lukevers/converse/routes"
"log"
"net/http"
"time"
)
var router *gin.Engine
func route() {
// If we're in production mode don't run gin in develop
if *production {
gin.SetMode(gin.ReleaseMode)
}
// Create new router
router = gin.Default()
// Compile html templates
router.LoadHTMLGlob("app/html/*.html")
// Add all routes
addRoutes()
// Add static routes
router.Static("/", "./public/")
// Create http server based off of net/http
addr := fmt.Sprintf("%s:%d", *host, *port)
s := &http.Server{
Addr: addr,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
// Log
log.Fatal(s.ListenAndServe())
}
func addRoutes() {
router.GET("/", routes.Index)
}