This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Response.go
53 lines (42 loc) · 1.45 KB
/
Response.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
package protocol
import (
"fmt"
"time"
)
//RequestSendOption is the option information for request sending (encoding, encryption, etc).
type RequestSendOption interface {
String() string
}
//RegistryInfo contains the information for registry.
//It will be send back from registry to registrant within the request.
//It should be implement by user.
type RegistryInfo interface {
//Returns the unique ID of the registry
GetRegistryID() string
//Returns the type of the service
GetServiceType() string
//Returns the option when the registrant send the request
GetRequestSendOption() RequestSendOption
//Returns the information of candidate registries
GetCandidates() []RegistryInfo
String() string
}
//Response is the response that registry send to registrant.
//It contains the information for registry "RegistryInfo", a connection flag "Reject" and a timeout value "Timeout".
type Response struct {
RegistryInfo RegistryInfo
Timeout time.Duration //下一次连接的时间限制
Reject bool //是否拒绝连接
}
//Get the value of connection flag "Reject".
func (r Response) IsReject() bool {
return r.Reject
}
//Get the value of timeout value "Timeout".
func (r Response) GetTimeout() time.Duration {
return r.Timeout
}
func (r Response) String() string {
return fmt.Sprintf(`{"type":"github.com/yindaheng98/gogistry/protocol.Response",
"RegistryInfo":%s,"Timeout":"%d","Reject":"%t"}`, r.RegistryInfo.String(), r.Timeout, r.Reject)
}