-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
51 lines (40 loc) · 1015 Bytes
/
server.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
package main
import (
"html/template"
"io"
"net/http"
"github.com/labstack/echo"
)
type (
TemplateRenderer struct {
templates *template.Template
}
)
// Render a template document
func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
// Add global methods if data is a map
if viewContext, isMap := data.(map[string]interface{}); isMap {
viewContext["reverse"] = c.Echo().Reverse
}
return t.templates.ExecuteTemplate(w, name, data)
}
func main() {
e := echo.New()
renderer := &TemplateRenderer{
templates: template.Must(template.ParseGlob("/app/**/*.html")),
}
e.Renderer = renderer
//----------
// Handlers
//----------
e.Static("/assets", "/app/public/assets/")
e.File("/favicon.ico", "/app/public/assets/images/favicon.png")
e.GET("/", func(c echo.Context) error {
return c.Render(http.StatusOK, "index", map[string]map[string]interface{}{
"data": {
"current": "home",
},
})
})
e.Logger.Fatal(e.Start(":8080"))
}