/
http.go
72 lines (59 loc) · 1.23 KB
/
http.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
68
69
70
71
72
package service
import (
"fmt"
"github.com/fagongzi/util/format"
"github.com/labstack/echo"
)
const (
apiVersion = "v1"
)
// InitHTTPRouter init http router
func InitHTTPRouter(server *echo.Echo, ui, uiPrefix string) {
initClusterRouter(server)
initServerRouter(server)
initBindRouter(server)
initRoutingRouter(server)
initAPIRouter(server)
initSystemRouter(server)
initStatic(server, ui, uiPrefix)
}
type limitQuery struct {
limit int64
afterID uint64
}
func idParamFactory(ctx echo.Context) (interface{}, error) {
value := ctx.Param("id")
if value == "" {
return nil, fmt.Errorf("missing id path value")
}
id, err := format.ParseStrUInt64(value)
if err != nil {
return nil, err
}
return id, nil
}
func limitQueryFactory(ctx echo.Context) (interface{}, error) {
query := &limitQuery{
limit: limit,
}
value := ctx.QueryParam("limit")
if value != "" {
l, err := format.ParseStrInt64(value)
if err != nil {
return nil, err
}
query.limit = l
}
value = ctx.QueryParam("after")
if value != "" {
l, err := format.ParseStrUInt64(value)
if err != nil {
return nil, err
}
query.afterID = l
}
return query, nil
}
func emptyParamFactory(ctx echo.Context) (interface{}, error) {
return nil, nil
}