-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
57 lines (49 loc) · 994 Bytes
/
router.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
51
52
53
54
55
56
57
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func (sol *solution) setupRoutes() error {
sol.loadTemplates("./templates/*")
sol.Gin.Static("/assets", "./assets")
sol.Gin.GET("/", func(c *gin.Context) {
sol.renderTemplate(
c,
http.StatusOK,
"home.html",
gin.H{},
)
})
sol.Gin.NoRoute(func(c *gin.Context) {
sol.renderTemplate(
c,
http.StatusNotFound,
"404.html",
gin.H{},
)
})
sol.Gin.GET("/pairs", func(c *gin.Context) {
pairs, err := sol.getExchangePairs()
if err != nil {
c.String(http.StatusInternalServerError, "failed to get pairs: "+err.Error())
return
}
log.Println(pairs)
sol.renderTemplate(
c,
http.StatusOK,
"pairs.html",
gin.H{
"pairs": pairs,
},
)
})
return nil
}
func (sol *solution) loadTemplates(pattern string) {
sol.Gin.LoadHTMLGlob(pattern)
}
func (sol *solution) renderTemplate(c *gin.Context, code int, name string, obj interface{}) {
c.HTML(code, name, obj)
}