-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (39 loc) · 1.28 KB
/
main.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
package main
import (
"github.com/gorilla/sessions"
"github.com/labstack/echo"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/middleware"
_ "github.com/mattn/go-sqlite3"
"github.com/yone-lab/isec-vulnerable-bbs/controllers"
"html/template"
"io"
)
type Template struct {
templates *template.Template
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
// refs: https://stackoverflow.com/questions/18175630/go-template-executetemplate-include-html
func noescape(str string) template.HTML {
return template.HTML(str)
}
func main() {
t := &Template{
templates: template.Must(template.New("main").Funcs(template.FuncMap{"noescape": noescape}).ParseGlob("public/views/*.html")),
}
e := echo.New()
e.Debug = true
e.Renderer = t
e.Static("/static", "assets")
e.Use(middleware.Logger())
e.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
e.GET("/", controllers.IndexGetHandler)
e.GET("/login", controllers.LoginGetHandler)
e.POST("/login", controllers.LoginPostHandler)
e.GET("/signup", controllers.SignupGetHandler)
e.POST("/signup", controllers.SignupPostHandler)
e.POST("/post", controllers.PostPostHandler)
e.Logger.Fatal(e.Start(":8080"))
}