-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmread.go
More file actions
66 lines (55 loc) · 1.28 KB
/
mread.go
File metadata and controls
66 lines (55 loc) · 1.28 KB
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
66
package main
import (
"errors"
"github.com/eknkc/amber"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/middleware"
"html/template"
"io"
"os"
)
type Views struct {
templates map[string]*template.Template
}
func (t *Views) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
for templateName, temp := range t.templates {
if name == templateName {
return temp.Execute(w, data)
}
}
return errors.New("Template not found")
}
func main() {
loadConfig()
e := echo.New()
e.Pre(middleware.RemoveTrailingSlash())
viewInfo := []struct {
name string
path string
}{
{"index", "./views/main.amber"},
{"search", "./views/search.amber"},
{"manga", "./views/manga.amber"},
}
t := &Views{make(map[string]*template.Template)}
compiler := amber.New()
for _, v := range viewInfo {
err := compiler.ParseFile(v.path)
if err != nil {
log.Error("Error parsing template file: ", err)
os.Exit(1)
}
tpl, err := compiler.Compile()
if err != nil {
log.Error("Error compiling template file: ", err)
os.Exit(1)
}
t.templates[v.name] = tpl
}
e.SetRenderer(t)
setupRoutes(e)
e.Static("/static", "static")
log.Success("Listening on", CONFIG.PORT)
e.Run(standard.New(":" + CONFIG.PORT))
}