33 lines
895 B
Go
33 lines
895 B
Go
package grpcclient
|
|
|
|
import (
|
|
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
|
"git.hlsq.asia/alex/service-common/discover"
|
|
"git.hlsq.asia/alex/service-common/discover/common"
|
|
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func GatewayNewClient(sid ...int64) (rspb.GatewayClient, error) {
|
|
var c *grpc.ClientConn
|
|
var err error
|
|
if len(sid) == 0 {
|
|
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameGateway)
|
|
} else {
|
|
c, err = discover.FindServer(common.KeyDiscoverGateway, sid...)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return rspb.NewGatewayClient(c), nil
|
|
}
|
|
|
|
func GatewayNewBroadcastClient() map[int64]rspb.GatewayClient {
|
|
clientM := make(map[int64]rspb.GatewayClient)
|
|
connM := discover.FindServerAll(common.KeyDiscoverGateway)
|
|
for sid, conn := range connM {
|
|
clientM[sid] = rspb.NewGatewayClient(conn)
|
|
}
|
|
return clientM
|
|
}
|