mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-20 05:07:05 +08:00
grpc
This commit is contained in:
parent
ee8ee48418
commit
2005a91891
@ -53,14 +53,15 @@ var _ MessageHandler = (*GrpcHandler)(nil)
|
|||||||
|
|
||||||
type GrpcHandler struct {
|
type GrpcHandler struct {
|
||||||
msgRpcClient *rpcclient.MessageRpcClient
|
msgRpcClient *rpcclient.MessageRpcClient
|
||||||
pushClient *rpcclient.PushClient
|
pushClient *rpcclient.PushRpcClient
|
||||||
validate *validator.Validate
|
validate *validator.Validate
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGrpcHandler(validate *validator.Validate, client discoveryregistry.SvcDiscoveryRegistry) *GrpcHandler {
|
func NewGrpcHandler(validate *validator.Validate, client discoveryregistry.SvcDiscoveryRegistry) *GrpcHandler {
|
||||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||||
|
pushRpcClient := rpcclient.NewPushRpcClient(client)
|
||||||
return &GrpcHandler{msgRpcClient: &msgRpcClient,
|
return &GrpcHandler{msgRpcClient: &msgRpcClient,
|
||||||
pushClient: rpcclient.NewPushClient(client), validate: validate}
|
pushClient: &pushRpcClient, validate: validate}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
|
func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
|
||||||
|
|||||||
@ -6,28 +6,33 @@ import (
|
|||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Push struct {
|
type Push struct {
|
||||||
|
conn *grpc.ClientConn
|
||||||
|
Client push.PushMsgServiceClient
|
||||||
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPushPush(client discoveryregistry.SvcDiscoveryRegistry) *PushClient {
|
func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
|
||||||
return &PushClient{
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
|
||||||
MetaClient: MetaClient{
|
if err != nil {
|
||||||
client: client,
|
panic(err)
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImPushName,
|
}
|
||||||
},
|
return &Push{
|
||||||
|
discov: discov,
|
||||||
|
conn: conn,
|
||||||
|
Client: push.NewPushMsgServiceClient(conn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PushClient) DelUserPushToken(ctx context.Context, req *push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) {
|
type PushRpcClient Push
|
||||||
cc, err := p.getConn(ctx)
|
|
||||||
if err != nil {
|
func NewPushRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) PushRpcClient {
|
||||||
return nil, err
|
return PushRpcClient(*NewPush(discov))
|
||||||
}
|
}
|
||||||
resp, err := push.NewPushMsgServiceClient(cc).DelUserPushToken(ctx, req)
|
|
||||||
if err != nil {
|
func (p *PushRpcClient) DelUserPushToken(ctx context.Context, req *push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) {
|
||||||
return nil, err
|
return p.Client.DelUserPushToken(ctx, req)
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user