-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (39 loc) · 1.21 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
50
package main
import (
"html/template"
"io"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"bitbucket.com/turntwo/quicksight-embeds/config"
m "bitbucket.com/turntwo/quicksight-embeds/middleware"
"bitbucket.com/turntwo/quicksight-embeds/web"
)
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)
}
func main() {
e := echo.New()
e.Renderer = &Template{
templates: template.Must(template.ParseGlob("public/views/*.html")),
}
e.Static("/assets", "public/dist")
cfg := config.New()
sessionStore := sessions.NewCookieStore([]byte(cfg.SessionKey))
e.Use(session.Middleware(sessionStore))
e.Use(middleware.Logger())
handler := web.NewHandler(cfg)
ah := web.AuthHandler{handler}
dh := web.DashboardHandler{handler}
// Authentication Handlers
e.GET("/", ah.Index)
e.POST("/authenticate", ah.SubmitLogin)
e.GET("/logout", ah.Logout)
// Dashboard handlers
e.GET("/dashboard", dh.Index, m.CognitoAuthentication(sessionStore, cfg))
e.Logger.Fatal(e.Start(":1323"))
}