forked from icexin/brpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.go
33 lines (26 loc) · 728 Bytes
/
protocol.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
package brpc
import (
"net"
"google.golang.org/grpc"
)
var (
protocols = map[string]Protocol{}
)
// Server is the interface that must be implemented by a protocol server.
type Server interface {
RegisterService(sd *grpc.ServiceDesc, ss interface{})
Serve(l net.Listener) error
}
// Protocol defines how to make rpc call and serve rpc call.
type Protocol interface {
Dial(target string, options ...DialOption) (grpc.ClientConnInterface, error)
NewServer(options ...ServerOption) Server
}
// RegisterProtocol registers a protocol.
func RegisterProtocol(name string, p Protocol) {
protocols[name] = p
}
// getProtocol returns a registered protocol.
func getProtocol(name string) Protocol {
return protocols[name]
}