forked from weibocom/motan-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoint.go
69 lines (54 loc) · 1.41 KB
/
endpoint.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
package endpoint
import (
motan "github.com/weibocom/motan-go/core"
mpro "github.com/weibocom/motan-go/protocol"
)
// ext name
const (
Grpc = "grpc"
Motan2 = "motan2"
Mock = "mockEndpoint"
)
func RegistDefaultEndpoint(extFactory motan.ExtentionFactory) {
extFactory.RegistExtEndpoint(Motan2, func(url *motan.URL) motan.EndPoint {
return &MotanEndpoint{url: url}
})
extFactory.RegistExtEndpoint(Grpc, func(url *motan.URL) motan.EndPoint {
return &GrpcEndPoint{url: url}
})
extFactory.RegistExtEndpoint(Mock, func(url *motan.URL) motan.EndPoint {
return &MockEndpoint{URL: url}
})
}
func GetRequestGroup(r motan.Request) string {
group := r.GetAttachment(mpro.MGroup)
if group == "" {
group = r.GetAttachment(motan.GroupKey)
}
return group
}
type MockEndpoint struct {
URL *motan.URL
MockResponse motan.Response
}
func (m *MockEndpoint) GetName() string {
return "mockEndpoint"
}
func (m *MockEndpoint) GetURL() *motan.URL {
return m.URL
}
func (m *MockEndpoint) SetURL(url *motan.URL) {
m.URL = url
}
func (m *MockEndpoint) IsAvailable() bool {
return true
}
func (m *MockEndpoint) SetProxy(proxy bool) {}
func (m *MockEndpoint) SetSerialization(s motan.Serialization) {}
func (m *MockEndpoint) Call(request motan.Request) motan.Response {
if m.MockResponse != nil {
return m.MockResponse
}
return &motan.MotanResponse{ProcessTime: 1, Value: "ok"}
}
func (m *MockEndpoint) Destroy() {}