-
Notifications
You must be signed in to change notification settings - Fork 0
/
example
53 lines (38 loc) · 1.32 KB
/
example
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
package main
import (
"fmt"
"code.minty.io/dingo"
"code.minty.io/dingo/views"
)
func index(ctx dingo.Context) {
views.Execute(ctx, "index.html", nil)
}
func test(ctx dingo.Context) {
views.Get("base.html").Reload(ctx)
views.Execute(ctx, "index.html", nil)
}
func testRouteData(ctx dingo.Context) {
fmt.Println(ctx.RouteData)
views.Execute(ctx, "index.html", nil)
}
func testRRoute(ctx dingo.Context, year, month, day, title string) {
fmt.Printf("%s-%s-%s %s\n", year, month, day, title)
views.Execute(ctx, "index.html", nil)
}
func main() {
s := dingo.New("0.0.0.0", 8000)
views.Path = "../templates"
// --- Routes ---
//views.New("base.html")
//views.Editable(views.New("index.html")).Extends("base.html")
views.NewEditable("base.html")
views.NewEditable("index.html").Extends("base.html")
s.ReRoute("^/$", index, "GET", "POST")
s.Get("^/test/$", test)
s.ReRoute("^/blog1/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/(?P<title>\\w+)/$", testRouteData, "GET")
s.RRoute("^/blog2/(\\d{4})/(\\d{2})/(\\d{2})/(\\w+)/$", testRRoute, "GET")
// ---- Editable ----
s.ReRoute("^/_dt/$", views.EditHandler, "GET", "POST")
//views.AddEditableView("base.html")
s.Serve()
}