This commit is contained in:
wangchuxiao 2023-06-20 21:15:23 +08:00
parent 84afa86db2
commit 5e634ac91f
10 changed files with 150 additions and 167 deletions

View File

@ -26,8 +26,8 @@ type Auth struct {
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (o *Auth) Client(ctx context.Context) (auth.AuthClient, error) { func (o *Auth) Client() auth.AuthClient {
return o.client, nil return o.client
} }
func (o *Auth) UserToken(c *gin.Context) { func (o *Auth) UserToken(c *gin.Context) {

View File

@ -12,56 +12,54 @@ import (
) )
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation { func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName) conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
return &Conversation{discov: discov} client := conversation.NewConversationClient(conn)
return &Conversation{discov: discov, conn: conn, client: client}
} }
type Conversation struct { type Conversation struct {
client conversation.ConversationClient
conn *grpc.ClientConn conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (o *Conversation) client(ctx context.Context) (conversation.ConversationClient, error) { func (o *Conversation) Client() conversation.ConversationClient {
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName) return o.client
if err != nil {
return nil, err
}
return conversation.NewConversationClient(c), nil
} }
func (o *Conversation) GetAllConversations(c *gin.Context) { func (o *Conversation) GetAllConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetAllConversations, o.client, c) a2r.Call(conversation.ConversationClient.GetAllConversations, o.Client, c)
} }
func (o *Conversation) GetConversation(c *gin.Context) { func (o *Conversation) GetConversation(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetConversation, o.client, c) a2r.Call(conversation.ConversationClient.GetConversation, o.Client, c)
} }
func (o *Conversation) GetConversations(c *gin.Context) { func (o *Conversation) GetConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetConversations, o.client, c) a2r.Call(conversation.ConversationClient.GetConversations, o.Client, c)
} }
// deprecated // deprecated
func (o *Conversation) SetConversation(c *gin.Context) { func (o *Conversation) SetConversation(c *gin.Context) {
a2r.Call(conversation.ConversationClient.SetConversation, o.client, c) a2r.Call(conversation.ConversationClient.SetConversation, o.Client, c)
} }
// deprecated // deprecated
func (o *Conversation) BatchSetConversations(c *gin.Context) { func (o *Conversation) BatchSetConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.BatchSetConversations, o.client, c) a2r.Call(conversation.ConversationClient.BatchSetConversations, o.Client, c)
} }
func (o *Conversation) SetRecvMsgOpt(c *gin.Context) { func (o *Conversation) SetRecvMsgOpt(c *gin.Context) {
a2r.Call(conversation.ConversationClient.SetRecvMsgOpt, o.client, c) a2r.Call(conversation.ConversationClient.SetRecvMsgOpt, o.Client, c)
} }
func (o *Conversation) ModifyConversationField(c *gin.Context) { func (o *Conversation) ModifyConversationField(c *gin.Context) {
a2r.Call(conversation.ConversationClient.ModifyConversationField, o.client, c) a2r.Call(conversation.ConversationClient.ModifyConversationField, o.Client, c)
} }
func (o *Conversation) SetConversations(c *gin.Context) { func (o *Conversation) SetConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.SetConversations, o.client, c) a2r.Call(conversation.ConversationClient.SetConversations, o.Client, c)
} }

View File

@ -13,70 +13,68 @@ import (
) )
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend { func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName) conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
return &Friend{discov: discov} client := friend.NewFriendClient(conn)
return &Friend{discov: discov, conn: conn, client: client}
} }
type Friend struct { type Friend struct {
conn *grpc.ClientConn conn *grpc.ClientConn
client friend.FriendClient
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (o *Friend) client(ctx context.Context) (friend.FriendClient, error) { func (o *Friend) Client() friend.FriendClient {
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImFriendName) return friend.NewFriendClient(o.conn)
if err != nil {
return nil, err
}
return friend.NewFriendClient(c), nil
} }
func (o *Friend) ApplyToAddFriend(c *gin.Context) { func (o *Friend) ApplyToAddFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.ApplyToAddFriend, o.client, c) a2r.Call(friend.FriendClient.ApplyToAddFriend, o.Client, c)
} }
func (o *Friend) RespondFriendApply(c *gin.Context) { func (o *Friend) RespondFriendApply(c *gin.Context) {
a2r.Call(friend.FriendClient.RespondFriendApply, o.client, c) a2r.Call(friend.FriendClient.RespondFriendApply, o.Client, c)
} }
func (o *Friend) DeleteFriend(c *gin.Context) { func (o *Friend) DeleteFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.DeleteFriend, o.client, c) a2r.Call(friend.FriendClient.DeleteFriend, o.Client, c)
} }
func (o *Friend) GetFriendApplyList(c *gin.Context) { func (o *Friend) GetFriendApplyList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyTo, o.client, c) a2r.Call(friend.FriendClient.GetPaginationFriendsApplyTo, o.Client, c)
} }
func (o *Friend) GetSelfApplyList(c *gin.Context) { func (o *Friend) GetSelfApplyList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.client, c) a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.Client, c)
} }
func (o *Friend) GetFriendList(c *gin.Context) { func (o *Friend) GetFriendList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriends, o.client, c) a2r.Call(friend.FriendClient.GetPaginationFriends, o.Client, c)
} }
func (o *Friend) SetFriendRemark(c *gin.Context) { func (o *Friend) SetFriendRemark(c *gin.Context) {
a2r.Call(friend.FriendClient.SetFriendRemark, o.client, c) a2r.Call(friend.FriendClient.SetFriendRemark, o.Client, c)
} }
func (o *Friend) AddBlack(c *gin.Context) { func (o *Friend) AddBlack(c *gin.Context) {
a2r.Call(friend.FriendClient.AddBlack, o.client, c) a2r.Call(friend.FriendClient.AddBlack, o.Client, c)
} }
func (o *Friend) GetPaginationBlacks(c *gin.Context) { func (o *Friend) GetPaginationBlacks(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.client, c) a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c)
} }
func (o *Friend) RemoveBlack(c *gin.Context) { func (o *Friend) RemoveBlack(c *gin.Context) {
a2r.Call(friend.FriendClient.RemoveBlack, o.client, c) a2r.Call(friend.FriendClient.RemoveBlack, o.Client, c)
} }
func (o *Friend) ImportFriends(c *gin.Context) { func (o *Friend) ImportFriends(c *gin.Context) {
a2r.Call(friend.FriendClient.ImportFriends, o.client, c) a2r.Call(friend.FriendClient.ImportFriends, o.Client, c)
} }
func (o *Friend) IsFriend(c *gin.Context) { func (o *Friend) IsFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.IsFriend, o.client, c) a2r.Call(friend.FriendClient.IsFriend, o.Client, c)
} }

View File

@ -13,108 +13,106 @@ import (
) )
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group { func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName) conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
return &Group{discov: discov} client := group.NewGroupClient(conn)
return &Group{discov: discov, conn: conn, client: client}
} }
type Group struct { type Group struct {
conn *grpc.ClientConn conn *grpc.ClientConn
client group.GroupClient
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (o *Group) client(ctx context.Context) (group.GroupClient, error) { func (o *Group) Client() group.GroupClient {
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImGroupName) return o.client
if err != nil {
return nil, err
}
return group.NewGroupClient(c), nil
} }
func (o *Group) CreateGroup(c *gin.Context) { func (o *Group) CreateGroup(c *gin.Context) {
a2r.Call(group.GroupClient.CreateGroup, o.client, c) a2r.Call(group.GroupClient.CreateGroup, o.Client, c)
} }
func (o *Group) SetGroupInfo(c *gin.Context) { func (o *Group) SetGroupInfo(c *gin.Context) {
a2r.Call(group.GroupClient.SetGroupInfo, o.client, c) a2r.Call(group.GroupClient.SetGroupInfo, o.Client, c)
} }
func (o *Group) JoinGroup(c *gin.Context) { func (o *Group) JoinGroup(c *gin.Context) {
a2r.Call(group.GroupClient.JoinGroup, o.client, c) a2r.Call(group.GroupClient.JoinGroup, o.Client, c)
} }
func (o *Group) QuitGroup(c *gin.Context) { func (o *Group) QuitGroup(c *gin.Context) {
a2r.Call(group.GroupClient.QuitGroup, o.client, c) a2r.Call(group.GroupClient.QuitGroup, o.Client, c)
} }
func (o *Group) ApplicationGroupResponse(c *gin.Context) { func (o *Group) ApplicationGroupResponse(c *gin.Context) {
a2r.Call(group.GroupClient.GroupApplicationResponse, o.client, c) a2r.Call(group.GroupClient.GroupApplicationResponse, o.Client, c)
} }
func (o *Group) TransferGroupOwner(c *gin.Context) { func (o *Group) TransferGroupOwner(c *gin.Context) {
a2r.Call(group.GroupClient.TransferGroupOwner, o.client, c) a2r.Call(group.GroupClient.TransferGroupOwner, o.Client, c)
} }
func (o *Group) GetRecvGroupApplicationList(c *gin.Context) { func (o *Group) GetRecvGroupApplicationList(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupApplicationList, o.client, c) a2r.Call(group.GroupClient.GetGroupApplicationList, o.Client, c)
} }
func (o *Group) GetUserReqGroupApplicationList(c *gin.Context) { func (o *Group) GetUserReqGroupApplicationList(c *gin.Context) {
a2r.Call(group.GroupClient.GetUserReqApplicationList, o.client, c) a2r.Call(group.GroupClient.GetUserReqApplicationList, o.Client, c)
} }
func (o *Group) GetGroupsInfo(c *gin.Context) { func (o *Group) GetGroupsInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupsInfo, o.client, c) a2r.Call(group.GroupClient.GetGroupsInfo, o.Client, c)
} }
func (o *Group) KickGroupMember(c *gin.Context) { func (o *Group) KickGroupMember(c *gin.Context) {
a2r.Call(group.GroupClient.KickGroupMember, o.client, c) a2r.Call(group.GroupClient.KickGroupMember, o.Client, c)
} }
func (o *Group) GetGroupMembersInfo(c *gin.Context) { func (o *Group) GetGroupMembersInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupMembersInfo, o.client, c) a2r.Call(group.GroupClient.GetGroupMembersInfo, o.Client, c)
} }
func (o *Group) GetGroupMemberList(c *gin.Context) { func (o *Group) GetGroupMemberList(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupMemberList, o.client, c) a2r.Call(group.GroupClient.GetGroupMemberList, o.Client, c)
} }
func (o *Group) InviteUserToGroup(c *gin.Context) { func (o *Group) InviteUserToGroup(c *gin.Context) {
a2r.Call(group.GroupClient.InviteUserToGroup, o.client, c) a2r.Call(group.GroupClient.InviteUserToGroup, o.Client, c)
} }
func (o *Group) GetJoinedGroupList(c *gin.Context) { func (o *Group) GetJoinedGroupList(c *gin.Context) {
a2r.Call(group.GroupClient.GetJoinedGroupList, o.client, c) a2r.Call(group.GroupClient.GetJoinedGroupList, o.Client, c)
} }
func (o *Group) DismissGroup(c *gin.Context) { func (o *Group) DismissGroup(c *gin.Context) {
a2r.Call(group.GroupClient.DismissGroup, o.client, c) a2r.Call(group.GroupClient.DismissGroup, o.Client, c)
} }
func (o *Group) MuteGroupMember(c *gin.Context) { func (o *Group) MuteGroupMember(c *gin.Context) {
a2r.Call(group.GroupClient.MuteGroupMember, o.client, c) a2r.Call(group.GroupClient.MuteGroupMember, o.Client, c)
} }
func (o *Group) CancelMuteGroupMember(c *gin.Context) { func (o *Group) CancelMuteGroupMember(c *gin.Context) {
a2r.Call(group.GroupClient.CancelMuteGroupMember, o.client, c) a2r.Call(group.GroupClient.CancelMuteGroupMember, o.Client, c)
} }
func (o *Group) MuteGroup(c *gin.Context) { func (o *Group) MuteGroup(c *gin.Context) {
a2r.Call(group.GroupClient.MuteGroup, o.client, c) a2r.Call(group.GroupClient.MuteGroup, o.Client, c)
} }
func (o *Group) CancelMuteGroup(c *gin.Context) { func (o *Group) CancelMuteGroup(c *gin.Context) {
a2r.Call(group.GroupClient.CancelMuteGroup, o.client, c) a2r.Call(group.GroupClient.CancelMuteGroup, o.Client, c)
} }
func (o *Group) SetGroupMemberInfo(c *gin.Context) { func (o *Group) SetGroupMemberInfo(c *gin.Context) {
a2r.Call(group.GroupClient.SetGroupMemberInfo, o.client, c) a2r.Call(group.GroupClient.SetGroupMemberInfo, o.Client, c)
} }
func (o *Group) GetGroupAbstractInfo(c *gin.Context) { func (o *Group) GetGroupAbstractInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupAbstractInfo, o.client, c) a2r.Call(group.GroupClient.GetGroupAbstractInfo, o.Client, c)
} }
//func (g *Group) SetGroupMemberNickname(c *gin.Context) { //func (g *Group) SetGroupMemberNickname(c *gin.Context) {
@ -126,9 +124,9 @@ func (o *Group) GetGroupAbstractInfo(c *gin.Context) {
//} //}
func (o *Group) GetJoinedSuperGroupList(c *gin.Context) { func (o *Group) GetJoinedSuperGroupList(c *gin.Context) {
a2r.Call(group.GroupClient.GetJoinedSuperGroupList, o.client, c) a2r.Call(group.GroupClient.GetJoinedSuperGroupList, o.Client, c)
} }
func (o *Group) GetSuperGroupsInfo(c *gin.Context) { func (o *Group) GetSuperGroupsInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetSuperGroupsInfo, o.client, c) a2r.Call(group.GroupClient.GetSuperGroupsInfo, o.Client, c)
} }

View File

@ -22,15 +22,17 @@ import (
) )
func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message { func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName) conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
return &Message{validate: validator.New(), discov: discov} client := msg.NewMsgClient(conn)
return &Message{validate: validator.New(), discov: discov, conn: conn, client: client}
} }
type Message struct { type Message struct {
conn *grpc.ClientConn conn *grpc.ClientConn
client msg.MsgClient
validate *validator.Validate validate *validator.Validate
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
@ -107,76 +109,72 @@ func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementS
return &pbData return &pbData
} }
func (m *Message) client(ctx context.Context) (msg.MsgClient, error) { func (m *Message) Client() msg.MsgClient {
c, err := m.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImMsgName) return m.client
if err != nil {
return nil, err
}
return msg.NewMsgClient(c), nil
} }
func (m *Message) GetSeq(c *gin.Context) { func (m *Message) GetSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMaxSeq, m.client, c) a2r.Call(msg.MsgClient.GetMaxSeq, m.Client, c)
} }
func (m *Message) PullMsgBySeqs(c *gin.Context) { func (m *Message) PullMsgBySeqs(c *gin.Context) {
a2r.Call(msg.MsgClient.PullMessageBySeqs, m.client, c) a2r.Call(msg.MsgClient.PullMessageBySeqs, m.Client, c)
} }
func (m *Message) RevokeMsg(c *gin.Context) { func (m *Message) RevokeMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.RevokeMsg, m.client, c) a2r.Call(msg.MsgClient.RevokeMsg, m.Client, c)
} }
func (m *Message) MarkMsgsAsRead(c *gin.Context) { func (m *Message) MarkMsgsAsRead(c *gin.Context) {
a2r.Call(msg.MsgClient.MarkMsgsAsRead, m.client, c) a2r.Call(msg.MsgClient.MarkMsgsAsRead, m.Client, c)
} }
func (m *Message) MarkConversationAsRead(c *gin.Context) { func (m *Message) MarkConversationAsRead(c *gin.Context) {
a2r.Call(msg.MsgClient.MarkConversationAsRead, m.client, c) a2r.Call(msg.MsgClient.MarkConversationAsRead, m.Client, c)
} }
func (m *Message) GetConversationsHasReadAndMaxSeq(c *gin.Context) { func (m *Message) GetConversationsHasReadAndMaxSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetConversationsHasReadAndMaxSeq, m.client, c) a2r.Call(msg.MsgClient.GetConversationsHasReadAndMaxSeq, m.Client, c)
} }
func (m *Message) SetConversationHasReadSeq(c *gin.Context) { func (m *Message) SetConversationHasReadSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.SetConversationHasReadSeq, m.client, c) a2r.Call(msg.MsgClient.SetConversationHasReadSeq, m.Client, c)
} }
func (m *Message) ClearConversationsMsg(c *gin.Context) { func (m *Message) ClearConversationsMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ClearConversationsMsg, m.client, c) a2r.Call(msg.MsgClient.ClearConversationsMsg, m.Client, c)
} }
func (m *Message) UserClearAllMsg(c *gin.Context) { func (m *Message) UserClearAllMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.UserClearAllMsg, m.client, c) a2r.Call(msg.MsgClient.UserClearAllMsg, m.Client, c)
} }
func (m *Message) DeleteMsgs(c *gin.Context) { func (m *Message) DeleteMsgs(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgs, m.client, c) a2r.Call(msg.MsgClient.DeleteMsgs, m.Client, c)
} }
func (m *Message) DeleteMsgPhysicalBySeq(c *gin.Context) { func (m *Message) DeleteMsgPhysicalBySeq(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgPhysicalBySeq, m.client, c) a2r.Call(msg.MsgClient.DeleteMsgPhysicalBySeq, m.Client, c)
} }
func (m *Message) DeleteMsgPhysical(c *gin.Context) { func (m *Message) DeleteMsgPhysical(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgPhysical, m.client, c) a2r.Call(msg.MsgClient.DeleteMsgPhysical, m.Client, c)
} }
func (m *Message) SetMessageReactionExtensions(c *gin.Context) { func (m *Message) SetMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, m.client, c) a2r.Call(msg.MsgClient.SetMessageReactionExtensions, m.Client, c)
} }
func (m *Message) GetMessageListReactionExtensions(c *gin.Context) { func (m *Message) GetMessageListReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, m.client, c) a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, m.Client, c)
} }
func (m *Message) AddMessageReactionExtensions(c *gin.Context) { func (m *Message) AddMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, m.client, c) a2r.Call(msg.MsgClient.AddMessageReactionExtensions, m.Client, c)
} }
func (m *Message) DeleteMessageReactionExtensions(c *gin.Context) { func (m *Message) DeleteMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, m.client, c) a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, m.Client, c)
} }
func (m *Message) SendMessage(c *gin.Context) { func (m *Message) SendMessage(c *gin.Context) {
@ -245,13 +243,13 @@ func (m *Message) SendMessage(c *gin.Context) {
} }
func (m *Message) ManagementBatchSendMsg(c *gin.Context) { func (m *Message) ManagementBatchSendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, m.client, c) a2r.Call(msg.MsgClient.SendMsg, m.Client, c)
} }
func (m *Message) CheckMsgIsSendSuccess(c *gin.Context) { func (m *Message) CheckMsgIsSendSuccess(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c) a2r.Call(msg.MsgClient.GetSendMsgStatus, m.Client, c)
} }
func (m *Message) GetUsersOnlineStatus(c *gin.Context) { func (m *Message) GetUsersOnlineStatus(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c) a2r.Call(msg.MsgClient.GetSendMsgStatus, m.Client, c)
} }

View File

@ -177,8 +177,6 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
s := NewStatistics(discov) s := NewStatistics(discov)
conversationGroup.Use(mw.GinParseToken(rdb)) conversationGroup.Use(mw.GinParseToken(rdb))
statisticsGroup.POST("/user_register", s.UserRegister) statisticsGroup.POST("/user_register", s.UserRegister)
} }
return r return r
} }

View File

@ -2,29 +2,34 @@ package api
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r" "github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"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/user" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"google.golang.org/grpc"
) )
func NewStatistics(discov discoveryregistry.SvcDiscoveryRegistry) *Statistics { func NewStatistics(discov discoveryregistry.SvcDiscoveryRegistry) *Statistics {
return &Statistics{discov: discov} conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
if err != nil {
panic(err)
}
client := user.NewUserClient(conn)
return &Statistics{discov: discov, client: client, conn: conn}
} }
type Statistics struct { type Statistics struct {
conn *grpc.ClientConn
client user.UserClient
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (s *Statistics) userClient(ctx context.Context) (user.UserClient, error) { func (s *Statistics) Client() user.UserClient {
conn, err := s.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName) return s.client
if err != nil {
return nil, err
}
return user.NewUserClient(conn), nil
} }
func (s *Statistics) UserRegister(c *gin.Context) { func (s *Statistics) UserRegister(c *gin.Context) {
a2r.Call(user.UserClient.UserRegisterCount, s.userClient, c) a2r.Call(user.UserClient.UserRegisterCount, s.Client, c)
} }

View File

@ -18,53 +18,51 @@ import (
) )
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third { func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName) conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
return &Third{discov: discov} client := third.NewThirdClient(conn)
return &Third{discov: discov, client: client, conn: conn}
} }
type Third struct { type Third struct {
conn *grpc.ClientConn conn *grpc.ClientConn
client third.ThirdClient
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (o *Third) client(ctx context.Context) (third.ThirdClient, error) { func (o *Third) Client() third.ThirdClient {
conn, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImThirdName) return o.client
if err != nil {
return nil, err
}
return third.NewThirdClient(conn), nil
} }
func (o *Third) ApplyPut(c *gin.Context) { func (o *Third) ApplyPut(c *gin.Context) {
a2r.Call(third.ThirdClient.ApplyPut, o.client, c) a2r.Call(third.ThirdClient.ApplyPut, o.Client, c)
} }
func (o *Third) GetPut(c *gin.Context) { func (o *Third) GetPut(c *gin.Context) {
a2r.Call(third.ThirdClient.GetPut, o.client, c) a2r.Call(third.ThirdClient.GetPut, o.Client, c)
} }
func (o *Third) ConfirmPut(c *gin.Context) { func (o *Third) ConfirmPut(c *gin.Context) {
a2r.Call(third.ThirdClient.ConfirmPut, o.client, c) a2r.Call(third.ThirdClient.ConfirmPut, o.Client, c)
} }
func (o *Third) GetHash(c *gin.Context) { func (o *Third) GetHash(c *gin.Context) {
a2r.Call(third.ThirdClient.GetHashInfo, o.client, c) a2r.Call(third.ThirdClient.GetHashInfo, o.Client, c)
} }
func (o *Third) FcmUpdateToken(c *gin.Context) { func (o *Third) FcmUpdateToken(c *gin.Context) {
a2r.Call(third.ThirdClient.FcmUpdateToken, o.client, c) a2r.Call(third.ThirdClient.FcmUpdateToken, o.Client, c)
} }
func (o *Third) SetAppBadge(c *gin.Context) { func (o *Third) SetAppBadge(c *gin.Context) {
a2r.Call(third.ThirdClient.SetAppBadge, o.client, c) a2r.Call(third.ThirdClient.SetAppBadge, o.Client, c)
} }
func (o *Third) GetURL(c *gin.Context) { func (o *Third) GetURL(c *gin.Context) {
if c.Request.Method == http.MethodPost { if c.Request.Method == http.MethodPost {
a2r.Call(third.ThirdClient.GetUrl, o.client, c) a2r.Call(third.ThirdClient.GetUrl, o.Client, c)
return return
} }
name := c.Query("name") name := c.Query("name")
@ -81,13 +79,8 @@ func (o *Third) GetURL(c *gin.Context) {
expires = 3600 * 1000 expires = 3600 * 1000
} }
attachment, _ := strconv.ParseBool(c.Query("attachment")) attachment, _ := strconv.ParseBool(c.Query("attachment"))
client, err := o.client(c)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
c.Set(constant.OperationID, operationID) c.Set(constant.OperationID, operationID)
resp, err := client.GetUrl(mcontext.SetOperationID(c, operationID), &third.GetUrlReq{Name: name, Expires: expires, Attachment: attachment}) resp, err := o.client.GetUrl(mcontext.SetOperationID(c, operationID), &third.GetUrlReq{Name: name, Expires: expires, Attachment: attachment})
if err != nil { if err != nil {
if errs.ErrArgs.Is(err) { if errs.ErrArgs.Is(err) {
c.String(http.StatusBadRequest, err.Error()) c.String(http.StatusBadRequest, err.Error())

View File

@ -12,54 +12,54 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"google.golang.org/grpc"
) )
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User { func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName) conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
// if err != nil { if err != nil {
// panic(err) panic(err)
// } }
return &User{discov: discov} client := user.NewUserClient(conn)
return &User{discov: discov, client: client, conn: conn}
} }
type User struct { type User struct {
conn *grpc.ClientConn
client user.UserClient
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
} }
func (u *User) client(ctx context.Context) (user.UserClient, error) { func (s *User) Client() user.UserClient {
conn, err := u.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName) return s.client
if err != nil {
return nil, err
}
return user.NewUserClient(conn), nil
} }
func (u *User) UserRegister(c *gin.Context) { func (u *User) UserRegister(c *gin.Context) {
a2r.Call(user.UserClient.UserRegister, u.client, c) a2r.Call(user.UserClient.UserRegister, u.Client, c)
} }
func (u *User) UpdateUserInfo(c *gin.Context) { func (u *User) UpdateUserInfo(c *gin.Context) {
a2r.Call(user.UserClient.UpdateUserInfo, u.client, c) a2r.Call(user.UserClient.UpdateUserInfo, u.Client, c)
} }
func (u *User) SetGlobalRecvMessageOpt(c *gin.Context) { func (u *User) SetGlobalRecvMessageOpt(c *gin.Context) {
a2r.Call(user.UserClient.SetGlobalRecvMessageOpt, u.client, c) a2r.Call(user.UserClient.SetGlobalRecvMessageOpt, u.Client, c)
} }
func (u *User) GetUsersPublicInfo(c *gin.Context) { func (u *User) GetUsersPublicInfo(c *gin.Context) {
a2r.Call(user.UserClient.GetDesignateUsers, u.client, c) a2r.Call(user.UserClient.GetDesignateUsers, u.Client, c)
} }
func (u *User) GetAllUsersID(c *gin.Context) { func (u *User) GetAllUsersID(c *gin.Context) {
a2r.Call(user.UserClient.GetDesignateUsers, u.client, c) a2r.Call(user.UserClient.GetDesignateUsers, u.Client, c)
} }
func (u *User) AccountCheck(c *gin.Context) { func (u *User) AccountCheck(c *gin.Context) {
a2r.Call(user.UserClient.AccountCheck, u.client, c) a2r.Call(user.UserClient.AccountCheck, u.Client, c)
} }
func (u *User) GetUsers(c *gin.Context) { func (u *User) GetUsers(c *gin.Context) {
a2r.Call(user.UserClient.GetPaginationUsers, u.client, c) a2r.Call(user.UserClient.GetPaginationUsers, u.Client, c)
} }
func (u *User) GetUsersOnlineStatus(c *gin.Context) { func (u *User) GetUsersOnlineStatus(c *gin.Context) {

View File

@ -12,7 +12,7 @@ import (
func Call[A, B, C any]( func Call[A, B, C any](
rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error), rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error),
client func(ctx context.Context) (C, error), client func() C,
c *gin.Context, c *gin.Context,
) { ) {
var req A var req A
@ -29,12 +29,7 @@ func Call[A, B, C any](
} }
} }
log.ZDebug(c, "gin bind json success", "req", req) log.ZDebug(c, "gin bind json success", "req", req)
cli, err := client(c) cli := client()
if err != nil {
log.ZError(c, "get conn error", err, "req", req)
apiresp.GinError(c, errs.ErrInternalServer.Wrap(err.Error())) // 获取RPC连接失败
return
}
log.ZDebug(c, "get conn success", "req", req) log.ZDebug(c, "get conn success", "req", req)
data, err := rpc(cli, c, &req) data, err := rpc(cli, c, &req)
if err != nil { if err != nil {