-
Notifications
You must be signed in to change notification settings - Fork 0
/
gofkRpc.go
60 lines (44 loc) · 1018 Bytes
/
gofkRpc.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
60
package gofks
import (
gofkConf "github.com/bhmy-shm/gofks/core/config"
"github.com/bhmy-shm/gofks/core/errorx"
"github.com/bhmy-shm/gofks/zrpc"
"google.golang.org/grpc"
)
func NewRpcServer(conf *gofkConf.Config) *Gofk {
gofks := &Gofk{}
gofks.LoadWatch(conf)
gofks.rpcServer = zrpc.NewRpcServer(conf)
return gofks
}
func (gk *Gofk) Register(servers ...zrpc.RpcRegisterInter) *Gofk {
if gk.rpcServer == nil {
errorx.Fatal(errorx.ErrCodeParamsErr)
return nil
}
gk.rpcServer.Register(servers...)
return gk
}
func (gk *Gofk) Attach(opts ...grpc.ServerOption) *Gofk {
if gk.rpcServer == nil {
errorx.Fatal(errorx.ErrCodeParamsErr)
return nil
}
gk.rpcServer.AddGrpcOptions(opts...)
return gk
}
func (gk *Gofk) Start() *Gofk {
if gk.rpcServer == nil {
errorx.Fatal(errorx.ErrRpcServerNotFound)
return nil
}
gk.applyAll()
gk.rpcServer.Start()
return gk
}
func (gk *Gofk) Stop() {
if gk.rpcServer == nil {
errorx.Fatal(errorx.ErrRpcServerNotFound)
}
gk.rpcServer.Stop()
}