This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.go
59 lines (49 loc) · 2.07 KB
/
transport.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
package transport
// Mode describes the way that a transport is being used.
type Mode bool
// The modes that can be passed to calls to Dial() and Close().
const (
ModeServer Mode = true
ModeClient = false
)
// A Handler responds to an RPC request.
//
// Process is invoked to handle an incoming request. The handler should process
// the request and must update the response message with either the response
// payload or an error.
type Handler interface {
Process(req ImmutableMessage, res Message)
}
// The HandlerFunc type is an adapter to allow the use of
// ordinary functions as RPC handlers. If f is a function
// with the appropriate signature, HandlerFunc(f) is a
// Handler that calls f.
type HandlerFunc func(req ImmutableMessage, res Message)
// Process calls f(req, res).
func (f HandlerFunc) Process(req ImmutableMessage, res Message) {
f(req, res)
}
// Provider defines an interface implemented by transports that can be used
// by usrv. The transport layer is responsible for the exchange of encoded
// messages between RPC clients and servers.
type Provider interface {
// Dial connects to the transport using the specified dial mode. When
// the dial mode is set to DialModeServer the transport will start
// relaying messages to registered bindings.
Dial(mode Mode) error
// Close terminates a dialed connection using the specified dial mode.
Close(mode Mode) error
// Bind listens for messages send to a particular service and
// endpoint combination and invokes the supplied handler to process them.
//
// Transports may implement versioning for bindings in order to support
// complex deployment flows such as blue-green deployments.
Bind(version, service, endpoint string, handler Handler) error
// Unbind removes a message handler previously registered by a call to Bind().
// Calling Unbind with a (version, service, endpoint) tuple that is not
// registered has no effect.
Unbind(version, service, endpoint string)
// Request performs an RPC and returns back a read-only channel for
// receiving the result.
Request(msg Message) <-chan ImmutableMessage
}