-
Notifications
You must be signed in to change notification settings - Fork 36
/
server.go
41 lines (33 loc) · 1.05 KB
/
server.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
package rpcx
import (
"google.golang.org/grpc"
)
type (
RegisterFn func(*grpc.Server)
Server interface {
AddOptions(options ...grpc.ServerOption)
AddStreamInterceptors(interceptors ...grpc.StreamServerInterceptor)
AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor)
Start(register RegisterFn) error
}
baseRpcServer struct {
address string
options []grpc.ServerOption
streamInterceptors []grpc.StreamServerInterceptor
unaryInterceptors []grpc.UnaryServerInterceptor
}
)
func newBaseRpcServer(address string) *baseRpcServer {
return &baseRpcServer{
address: address,
}
}
func (s *baseRpcServer) AddOptions(options ...grpc.ServerOption) {
s.options = append(s.options, options...)
}
func (s *baseRpcServer) AddStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) {
s.streamInterceptors = append(s.streamInterceptors, interceptors...)
}
func (s *baseRpcServer) AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) {
s.unaryInterceptors = append(s.unaryInterceptors, interceptors...)
}