-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreg_builder.go
90 lines (77 loc) · 1.55 KB
/
reg_builder.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package qn
import (
"github.com/gin-gonic/gin"
"github.com/qunv/qn/protocol"
"github.com/qunv/qn/protocol/eb"
"github.com/qunv/qn/protocol/http"
"github.com/qunv/qn/protocol/ws"
)
type regBuilder interface {
Tags(...string) regBuilder
MiddleWare(...gin.HandlerFunc) regBuilder
New() Registry
}
func WithEndpoint(endpoint string) _withRegFunc {
return func(reg *reg) {
reg.endpoint = endpoint
}
}
func WithMethod(method protocol.Method) _withRegFunc {
return func(reg *reg) {
reg.method = method
}
}
func WithTags(tags ...string) _withRegFunc {
return func(reg *reg) {
reg.tags = tags
}
}
func WithMiddleWare(middlewares ...gin.HandlerFunc) _withRegFunc {
return func(reg *reg) {
reg.middlewares = middlewares
}
}
func Register(fns ..._withRegFunc) Registry {
reg := new(reg)
for _, with := range fns {
with(reg)
}
return reg
}
// HTTP_GET is a builder function that apply HTTP protocol and method GET
func HTTP_GET(endpoint string) regBuilder {
return ®{
method: http.GET,
endpoint: endpoint,
}
}
func HTTP_POST(endpoint string) regBuilder {
return ®{
method: http.POST,
endpoint: endpoint,
}
}
func HTTP_PUT(endpoint string) regBuilder {
return ®{
method: http.PUT,
endpoint: endpoint,
}
}
func HTTP_DELETE(endpoint string) regBuilder {
return ®{
method: http.DELETE,
endpoint: endpoint,
}
}
func WS(endpoint string) regBuilder {
return ®{
method: ws.WS,
endpoint: endpoint,
}
}
func EVENT_BUS(endpoint string) regBuilder {
return ®{
method: eb.EvenBus,
endpoint: endpoint,
}
}