-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (53 loc) · 1.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"html/template"
"io"
"net/http"
echo "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/nckslvrmn/go_ots/pkg/routes"
"github.com/nckslvrmn/go_ots/pkg/utils"
)
type TemplateRegistry struct {
templates map[string]*template.Template
}
// Render implements the echo.Renderer interface
func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates[name].Execute(w, data)
}
func main() {
e := echo.New()
err := utils.LoadEnv()
if err != nil {
e.Logger.Fatal(err)
}
templates := make(map[string]*template.Template)
t := &TemplateRegistry{
templates: templates,
}
templates["index"] = template.Must(template.ParseFiles("views/layout.html", "views/index.html"))
templates["files"] = template.Must(template.ParseFiles("views/layout.html", "views/files.html"))
templates["secret"] = template.Must(template.ParseFiles("views/layout.html", "views/secret.html"))
e.Static("/static", "static")
e.Renderer = t
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.HideBanner = true
e.HidePort = true
e.GET("/", index)
e.GET("/files", files)
e.GET("/secret/:secret_id", secret)
e.POST("/encrypt", routes.EncryptString)
e.POST("/encrypt_file", routes.EncryptFile)
e.POST("/decrypt", routes.Decrypt)
e.Logger.Fatal(e.Start(":6666"))
}
func index(c echo.Context) error {
return c.Render(http.StatusOK, "index", nil)
}
func files(c echo.Context) error {
return c.Render(http.StatusOK, "files", nil)
}
func secret(c echo.Context) error {
return c.Render(http.StatusOK, "secret", nil)
}