-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathroute.go
41 lines (34 loc) · 982 Bytes
/
route.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
package webapi
import (
"github.com/farseer-go/webapi/context"
"github.com/farseer-go/webapi/filter"
)
// Route 路由配置
type Route struct {
Method string // Method类型(GET|POST|PUT|DELETE)
Url string // 路由地址
Action any // Handle
Message string // api返回的StatusMessage
Filters []context.IFilter // 过滤器(对单个路由的执行单元)
Params []string // Handle的入参
}
// UseJwt 使用Jwt
func (receiver Route) UseJwt() Route {
receiver.Filters = append(receiver.Filters, filter.JwtFilter{})
return receiver
}
// POST 使用POST
func (receiver Route) POST() Route {
receiver.Method = "POST"
return receiver
}
// GET 使用GET
func (receiver Route) GET() Route {
receiver.Method = "GET"
return receiver
}
// Filter 添加过滤器
func (receiver Route) Filter(filter context.IFilter) Route {
receiver.Filters = append(receiver.Filters, filter)
return receiver
}