-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
55 lines (44 loc) · 1.12 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
package main
import (
"fmt"
"reflect"
"strings"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/view"
)
func main() {
tmpl := iris.Jet("./views", ".jet")
tmpl.Reload(true)
val := reflect.ValueOf(ViewBuiler{})
fns := val.Type()
for i := 0; i < fns.NumMethod(); i++ {
method := fns.Method(i)
tmpl.AddFunc(strings.ToLower(method.Name), val.Method(i).Interface())
}
app := iris.New()
app.RegisterView(tmpl)
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("index.jet"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
})
app.Listen(":8080")
}
type ViewBuiler struct {
}
func (ViewBuiler) Asset(a view.JetArguments) reflect.Value {
path := a.Get(0).String()
// fmt.Println(os.Getenv("APP_URL"))
return reflect.ValueOf(path)
}
func (ViewBuiler) Style(a view.JetArguments) reflect.Value {
path := a.Get(0).String()
s := fmt.Sprintf(`<link href="%v" rel="stylesheet">`, path)
return reflect.ValueOf(s)
}
func (ViewBuiler) Script(a view.JetArguments) reflect.Value {
path := a.Get(0).String()
s := fmt.Sprintf(`<script src="%v"></script>`, path)
return reflect.ValueOf(s)
}