feat grpc客户端整理
This commit is contained in:
33
net/grpc/grpc_client/client_scene.go
Normal file
33
net/grpc/grpc_client/client_scene.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package grpc_client
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/mmorpg/service-common/discover"
|
||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/resolver"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
)
|
||||
|
||||
func SceneNewClient(sid ...string) (grpc_pb.SceneClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverScene, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return grpc_pb.NewSceneClient(c), nil
|
||||
}
|
||||
|
||||
func SceneNewClientLB() (grpc_pb.SceneClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameScene)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return grpc_pb.NewSceneClient(c), nil
|
||||
}
|
||||
|
||||
func SceneNewBroadcastClient() map[string]grpc_pb.SceneClient {
|
||||
clientM := make(map[string]grpc_pb.SceneClient)
|
||||
connM := discover.FindServerAll(common.KeyDiscoverScene)
|
||||
for sid, conn := range connM {
|
||||
clientM[sid] = grpc_pb.NewSceneClient(conn)
|
||||
}
|
||||
return clientM
|
||||
}
|
||||
Reference in New Issue
Block a user