mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
grpc conn reuse
This commit is contained in:
+12
-32
@@ -11,27 +11,23 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type GroupClient struct {
|
||||
MetaClient
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewGroupClient(client discoveryregistry.SvcDiscoveryRegistry) *GroupClient {
|
||||
return &GroupClient{
|
||||
MetaClient: MetaClient{
|
||||
client: client,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
},
|
||||
func NewGroupClient(discov discoveryregistry.SvcDiscoveryRegistry) *GroupClient {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &GroupClient{conn: conn}
|
||||
}
|
||||
|
||||
func (g *GroupClient) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
|
||||
cc, err := g.getConn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
||||
resp, err := group.NewGroupClient(g.conn).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
||||
GroupIDs: groupIDs,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -66,11 +62,7 @@ func (g *GroupClient) GetGroupInfoMap(ctx context.Context, groupIDs []string, co
|
||||
}
|
||||
|
||||
func (g *GroupClient) GetGroupMemberInfos(ctx context.Context, groupID string, userIDs []string, complete bool) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
|
||||
resp, err := group.NewGroupClient(g.conn).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
|
||||
GroupID: groupID,
|
||||
UserIDs: userIDs,
|
||||
})
|
||||
@@ -106,11 +98,7 @@ func (g *GroupClient) GetGroupMemberInfoMap(ctx context.Context, groupID string,
|
||||
}
|
||||
|
||||
func (g *GroupClient) GetOwnerAndAdminInfos(ctx context.Context, groupID string) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
resp, err := group.NewGroupClient(g.conn).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
GroupID: groupID,
|
||||
RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin},
|
||||
})
|
||||
@@ -121,11 +109,7 @@ func (g *GroupClient) GetOwnerAndAdminInfos(ctx context.Context, groupID string)
|
||||
}
|
||||
|
||||
func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
resp, err := group.NewGroupClient(g.conn).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
GroupID: groupID,
|
||||
RoleLevels: []int32{constant.GroupOwner},
|
||||
})
|
||||
@@ -133,11 +117,7 @@ func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.
|
||||
}
|
||||
|
||||
func (g *GroupClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
cc, err := g.getConn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
|
||||
resp, err := group.NewGroupClient(g.conn).GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
|
||||
GroupID: groupID,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user