forked from andeya/faygo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
67 lines (61 loc) · 2.33 KB
/
router.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
66
67
package router
import (
"github.com/henrylee2cn/faygo"
mw "github.com/henrylee2cn/faygo/ext/middleware"
"github.com/henrylee2cn/faygo/samples/demo/handler"
"github.com/henrylee2cn/faygo/samples/demo/middleware"
)
// Register the route in a tree style
func Route1(frame *faygo.Framework) {
frame.
Filter(middleware.Root2Index).
Route(
// frame.NewNamedAPI("index", "*", "/", handler.Index()),
frame.NewNamedAPI("index", "*", "/index", handler.Index()),
frame.NewGroup("home",
frame.NewNamedGET("html", "render", &handler.Render{}),
frame.NewNamedAPI("params", "GET POST", "param/:id/*additional", &handler.Param{
Paragraph: []string{"default_paragraph"},
}),
),
frame.NewNamedGET("websocket", "/ws", handler.WebsocketPage()),
frame.NewNamedGET("websocket_server", "/ws_server", handler.Websocket),
frame.NewNamedPOST("binds the body in JSON format", "/body", &handler.Body{}),
frame.NewStaticFS("/public", faygo.DirFS("./static/public")),
frame.NewStatic("/syso", "../../_syso"),
frame.NewNamedStaticFS("render fs test", "/renderfs", faygo.RenderFS(
"./static/renderfs",
".html", // "*"
faygo.Map{"title": "RenderFS page"},
)).Use(mw.AutoHTMLSuffix()),
frame.NewNamedStaticFS("markdown fs test", "/md", faygo.MarkdownFS(
"./static/markdown",
)),
frame.NewNamedAPI("reverse proxy", "GETOPTIONS", "/search", handler.Search(0)).Use(mw.CrossOrigin),
)
}
// Register the route in a chain style
func Route2(frame *faygo.Framework) {
frame.Filter(middleware.Root2Index)
// frame.NamedAPI("index", "*", "/", handler.Index())
frame.NamedAPI("index", "*", "/index", handler.Index())
home := frame.Group("home")
{
home.NamedGET("html", "render", &handler.Render{})
home.NamedAPI("params", "GET POST", "param/:id/*additional", &handler.Param{
Paragraph: []string{"abc"},
})
}
frame.NamedPOST("binds the body in JSON format", "/body", &handler.Body{})
frame.StaticFS("/public", faygo.DirFS("./static/public"))
frame.Static("/syso", "../../_syso")
frame.NamedAPI("reverse proxy", "GET OPTIONS", "/search", handler.Search(0)).Use(mw.CrossOrigin)
frame.NamedStaticFS("render fs test", "/renderfs", faygo.RenderFS(
"./static/renderfs",
".html", // "*"
faygo.Map{"title": "RenderFS page"},
))
frame.NamedStaticFS("markdown fs test", "/md", faygo.MarkdownFS(
"./static/markdown",
))
}