-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (48 loc) · 938 Bytes
/
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
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"github.com/flosch/pongo2"
"github.com/labstack/echo"
)
var (
html string
port = flag.String("p", ":8000", "port flag")
)
const (
htmlpath = "views/index.html"
staticpath = "views/static/"
content = "content.json"
cvpath = "cv.pdf"
)
func site(c echo.Context) error {
return c.HTML(200, html)
}
func main() {
flag.Parse()
html = parsehtml()
e := echo.New()
e.Static("static", staticpath)
e.GET("/", site)
e.GET("/cv", func(c echo.Context) error {
return c.Attachment(cvpath, cvpath)
})
e.Logger.Fatal(e.Start(*port))
}
func parsehtml() string {
tpl := pongo2.Must(pongo2.FromFile(htmlpath))
data, err := ioutil.ReadFile(content)
if err != nil {
panic(err)
}
params := pongo2.Context{}
if err := json.Unmarshal(data, ¶ms); err != nil {
panic(err)
}
out, err := tpl.Execute(params)
if err != nil {
panic(err)
}
return out
}