Documentation ¶
Overview ¶
Package protocol is the basic of the gogistry. Before using gogistry, you should implement the interfaces using the transmission protocol you like (i.e. http, grpc, etc) in this package first.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReceivedRequest ¶
ReceivedRequest is used to store the request and error received by registry.
type ReceivedResponse ¶
ReceivedResponse is used to store the response and error received by registrant.
type RegistrantInfo ¶
type RegistrantInfo interface { //Returns the unique ID of the registrant GetRegistrantID() string //Returns the type of the service GetServiceType() string //Returns the option when the registry send back the response GetResponseSendOption() ResponseSendOption String() string }
RegistrantInfo contains the information for registrant. It will be send from registrant to registry within the request. It should be implement by user.
type RegistryInfo ¶
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 }
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 Request ¶
type Request struct { RegistrantInfo RegistrantInfo Disconnect bool }
Request is the request that registrant send to registry. It contains the information for registrant "RegistrantInfo" and a connection flag "Disconnect".
func (Request) IsDisconnect ¶
Get the value of connection flag "Disconnect".
type RequestProtocol ¶
type RequestProtocol interface { //In the implementation of this method, you should: // //1. Get a `TobeSendRequest` from the `requestChan` // //2. Get a `Request` and a `RequestSendOption` from `TobeSendRequest` // //3. Send the `Request` according to `RequestSendOption` via your protocol // //4. Waiting for a response in your protocol, and enclose the response into a `Response`, if there is an error occured, you should generate an `error` // //5. Enclose the `Response` and the `error` (if exists) into a `ReceivedResponse` // //6. Put the `ReceivedResponse` into the `responseChan` Request(ctx context.Context, requestChan <-chan TobeSendRequest, responseChan chan<- ReceivedResponse) }
RequestProtocol defines how a request should be sent from registrant to registry (by http, grpc, etc). It should be implement by user.
Higher-level protocol (`"heart/requester".Heart`) will call this function to send a request according to some option (they will be a `Request` and a `RequestSendOption`, enclosed into `TobeSendRequest`) via lower-level protocol (i.e. http, grpc, etc, implemented by you), and receive the response.
type RequestSendOption ¶
type RequestSendOption interface {
String() string
}
RequestSendOption is the option information for request sending (encoding, encryption, etc).
type Response ¶
type Response struct { RegistryInfo RegistryInfo Timeout time.Duration //下一次连接的时间限制 Reject bool //是否拒绝连接 }
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".
func (Response) GetTimeout ¶
Get the value of timeout value "Timeout".
type ResponseProtocol ¶
type ResponseProtocol interface { //In the implementation of this method, you should: // //1. Waiting for a request in your protocol, if there is an error occured, you should generate an `error` // //2. Enclose the request into a `Request` // //3. Enclose the `Request` and the `error` (if exists) into a `ReceivedRequest` // //4. Put the `ReceivedRequest` into `requestChan` // //5. Waiting for `responseChan` to send back a `TobeSendResponse` // //6. Get a `Response` and a `ResponseSendOption` from the `TobeSendResponse` // //7. Send back the `Response` according to the `ResponseSendOption` via your protocol Response(ctx context.Context, requestChan chan<- ReceivedRequest, responseChan <-chan TobeSendResponse) }
ResponseProtocol defines how a response should be sent back from registrant to registry (by http, grpc, etc). It should be implement by user.
Higher-level protocol(`"heart/responser".Heart`) will call this function in a loop, to receive the request (`Request`) from lower-level protocol (i.e. http, grpc, etc, implemented by you) from registrant and send back the generated response and sending option (`Response` and `ResponseSendOption`).
type ResponseSendOption ¶
type ResponseSendOption interface {
String() string
}
ResponseSendOption is the option information for response sending (encoding, encryption, etc).
type TobeSendRequest ¶
type TobeSendRequest struct { Request Request Option RequestSendOption }
TobeSendRequest is used to store the request that is going to be sent by registrant to registry. Option is the option information for sending (encoding, encryption, etc).
func (TobeSendRequest) String ¶
func (r TobeSendRequest) String() string
type TobeSendResponse ¶
type TobeSendResponse struct { Response Response Option ResponseSendOption }
TobeSendResponse is used to store the response that is going to be sent back by registry to registrant. Option is the option information for sending (encoding, encryption, etc).
func (TobeSendResponse) String ¶
func (r TobeSendResponse) String() string