-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcpug_taiwan.go
48 lines (37 loc) · 1017 Bytes
/
gcpug_taiwan.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 (
"github.com/gin-gonic/gin"
"github.com/rainbowism/gin-pongo2"
"google.golang.org/appengine"
"net/http"
"strings"
)
func indexHandler(c *gin.Context) {
c.HTML(http.StatusOK, "index.tpl", render.Context{})
}
func ioHandler(c *gin.Context) {
c.HTML(http.StatusOK, "io.tpl", render.Context{})
}
func noRouteHandler(c *gin.Context) {
c.HTML(http.StatusNotFound, "error.tpl", render.Context{"statusCode":404,"errorMessage":"Page not found"})
}
func GetMainEngine() *gin.Engine {
// check appengine mode
s := strings.ToLower(appengine.ServerSoftware())
if !strings.HasPrefix(s, "development") {
gin.SetMode(gin.ReleaseMode)
}
// Starts a new Gin instance with no middle-ware
r := gin.New()
r.HTMLRender = render.NewDebug("templates")
// Define your handlers
r.Static("/public", "public")
r.GET("/", indexHandler)
r.GET("/io2016", ioHandler)
r.NoRoute(noRouteHandler)
return r
}
func init() {
// Handle all requests using net/http
http.Handle("/", GetMainEngine())
}