-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.go
57 lines (45 loc) · 1.33 KB
/
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 (
"io"
"mime"
"text/template"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/tomato3713/cw_for_web/handler"
)
type Template struct {
templates *template.Template
}
func newRouter() *echo.Echo {
// for windows probrem: return incorrect MIME Type "text/plain"
mime.AddExtensionType(".js", "application/javascript")
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Secure())
// service worker
e.Static("/assets", "static/assets")
e.File("/manifest.json", "static/manifest.json")
e.File("/favicon.ico", "static/assets/img/icon/favicon.ico")
e.GET("/", handler.Index)
e.GET("/runner", handler.Runner)
e.GET("/tutor", handler.Tutor)
e.GET("/history", handler.History)
// authorization
e.GET("/#", handler.#)
e.POST("/#", handler.#Process)
e.GET("/#", handler.Login)
e.POST("/#", handler.LoginProcess)
e.GET("/profile", handler.Profile)
api := e.Group("/api")
api.Use(middleware.JWTWithConfig(handler.Config))
api.GET("records", handler.GetRecords)
t := &Template{
templates: template.Must(template.ParseGlob("static/views/*.html")),
}
e.Renderer = t
return e
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}