This commit is contained in:
wangchuxiao
2023-06-20 22:12:01 +08:00
parent 5e634ac91f
commit ee8ee48418
31 changed files with 401 additions and 565 deletions
+8 -24
View File
@@ -1,43 +1,27 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
if err != nil {
panic(err)
}
client := auth.NewAuthClient(conn)
return &Auth{discov: discov, conn: conn, client: client}
type AuthApi rpcclient.Auth
func NewAuthApi(discov discoveryregistry.SvcDiscoveryRegistry) AuthApi {
return AuthApi(*rpcclient.NewAuth(discov))
}
type Auth struct {
conn *grpc.ClientConn
client auth.AuthClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Auth) Client() auth.AuthClient {
return o.client
}
func (o *Auth) UserToken(c *gin.Context) {
func (o *AuthApi) UserToken(c *gin.Context) {
a2r.Call(auth.AuthClient.UserToken, o.Client, c)
}
func (o *Auth) ParseToken(c *gin.Context) {
func (o *AuthApi) ParseToken(c *gin.Context) {
a2r.Call(auth.AuthClient.ParseToken, o.Client, c)
}
func (o *Auth) ForceLogout(c *gin.Context) {
func (o *AuthApi) ForceLogout(c *gin.Context) {
a2r.Call(auth.AuthClient.ForceLogout, o.Client, c)
}
+13 -29
View File
@@ -1,65 +1,49 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
panic(err)
}
client := conversation.NewConversationClient(conn)
return &Conversation{discov: discov, conn: conn, client: client}
type ConversationApi rpcclient.Conversation
func NewConversationApi(discov discoveryregistry.SvcDiscoveryRegistry) ConversationApi {
return ConversationApi(*rpcclient.NewConversation(discov))
}
type Conversation struct {
client conversation.ConversationClient
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Conversation) Client() conversation.ConversationClient {
return o.client
}
func (o *Conversation) GetAllConversations(c *gin.Context) {
func (o *ConversationApi) GetAllConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetAllConversations, o.Client, c)
}
func (o *Conversation) GetConversation(c *gin.Context) {
func (o *ConversationApi) GetConversation(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetConversation, o.Client, c)
}
func (o *Conversation) GetConversations(c *gin.Context) {
func (o *ConversationApi) GetConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetConversations, o.Client, c)
}
// deprecated
func (o *Conversation) SetConversation(c *gin.Context) {
func (o *ConversationApi) SetConversation(c *gin.Context) {
a2r.Call(conversation.ConversationClient.SetConversation, o.Client, c)
}
// deprecated
func (o *Conversation) BatchSetConversations(c *gin.Context) {
func (o *ConversationApi) BatchSetConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.BatchSetConversations, o.Client, c)
}
func (o *Conversation) SetRecvMsgOpt(c *gin.Context) {
func (o *ConversationApi) SetRecvMsgOpt(c *gin.Context) {
a2r.Call(conversation.ConversationClient.SetRecvMsgOpt, o.Client, c)
}
func (o *Conversation) ModifyConversationField(c *gin.Context) {
func (o *ConversationApi) ModifyConversationField(c *gin.Context) {
a2r.Call(conversation.ConversationClient.ModifyConversationField, o.Client, c)
}
func (o *Conversation) SetConversations(c *gin.Context) {
func (o *ConversationApi) SetConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.SetConversations, o.Client, c)
}
+17 -33
View File
@@ -1,80 +1,64 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
)
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
panic(err)
}
client := friend.NewFriendClient(conn)
return &Friend{discov: discov, conn: conn, client: client}
type FriendApi rpcclient.Friend
func NewFriendApi(discov discoveryregistry.SvcDiscoveryRegistry) FriendApi {
return FriendApi(*rpcclient.NewFriend(discov))
}
type Friend struct {
conn *grpc.ClientConn
client friend.FriendClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Friend) Client() friend.FriendClient {
return friend.NewFriendClient(o.conn)
}
func (o *Friend) ApplyToAddFriend(c *gin.Context) {
func (o *FriendApi) ApplyToAddFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.ApplyToAddFriend, o.Client, c)
}
func (o *Friend) RespondFriendApply(c *gin.Context) {
func (o *FriendApi) RespondFriendApply(c *gin.Context) {
a2r.Call(friend.FriendClient.RespondFriendApply, o.Client, c)
}
func (o *Friend) DeleteFriend(c *gin.Context) {
func (o *FriendApi) DeleteFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.DeleteFriend, o.Client, c)
}
func (o *Friend) GetFriendApplyList(c *gin.Context) {
func (o *FriendApi) GetFriendApplyList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyTo, o.Client, c)
}
func (o *Friend) GetSelfApplyList(c *gin.Context) {
func (o *FriendApi) GetSelfApplyList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.Client, c)
}
func (o *Friend) GetFriendList(c *gin.Context) {
func (o *FriendApi) GetFriendList(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationFriends, o.Client, c)
}
func (o *Friend) SetFriendRemark(c *gin.Context) {
func (o *FriendApi) SetFriendRemark(c *gin.Context) {
a2r.Call(friend.FriendClient.SetFriendRemark, o.Client, c)
}
func (o *Friend) AddBlack(c *gin.Context) {
func (o *FriendApi) AddBlack(c *gin.Context) {
a2r.Call(friend.FriendClient.AddBlack, o.Client, c)
}
func (o *Friend) GetPaginationBlacks(c *gin.Context) {
func (o *FriendApi) GetPaginationBlacks(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c)
}
func (o *Friend) RemoveBlack(c *gin.Context) {
func (o *FriendApi) RemoveBlack(c *gin.Context) {
a2r.Call(friend.FriendClient.RemoveBlack, o.Client, c)
}
func (o *Friend) ImportFriends(c *gin.Context) {
func (o *FriendApi) ImportFriends(c *gin.Context) {
a2r.Call(friend.FriendClient.ImportFriends, o.Client, c)
}
func (o *Friend) IsFriend(c *gin.Context) {
func (o *FriendApi) IsFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.IsFriend, o.Client, c)
}
+28 -44
View File
@@ -1,117 +1,101 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
)
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
if err != nil {
panic(err)
}
client := group.NewGroupClient(conn)
return &Group{discov: discov, conn: conn, client: client}
type GroupApi rpcclient.Group
func NewGroupApi(discov discoveryregistry.SvcDiscoveryRegistry) GroupApi {
return GroupApi(*rpcclient.NewGroup(discov))
}
type Group struct {
conn *grpc.ClientConn
client group.GroupClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Group) Client() group.GroupClient {
return o.client
}
func (o *Group) CreateGroup(c *gin.Context) {
func (o *GroupApi) CreateGroup(c *gin.Context) {
a2r.Call(group.GroupClient.CreateGroup, o.Client, c)
}
func (o *Group) SetGroupInfo(c *gin.Context) {
func (o *GroupApi) SetGroupInfo(c *gin.Context) {
a2r.Call(group.GroupClient.SetGroupInfo, o.Client, c)
}
func (o *Group) JoinGroup(c *gin.Context) {
func (o *GroupApi) JoinGroup(c *gin.Context) {
a2r.Call(group.GroupClient.JoinGroup, o.Client, c)
}
func (o *Group) QuitGroup(c *gin.Context) {
func (o *GroupApi) QuitGroup(c *gin.Context) {
a2r.Call(group.GroupClient.QuitGroup, o.Client, c)
}
func (o *Group) ApplicationGroupResponse(c *gin.Context) {
func (o *GroupApi) ApplicationGroupResponse(c *gin.Context) {
a2r.Call(group.GroupClient.GroupApplicationResponse, o.Client, c)
}
func (o *Group) TransferGroupOwner(c *gin.Context) {
func (o *GroupApi) TransferGroupOwner(c *gin.Context) {
a2r.Call(group.GroupClient.TransferGroupOwner, o.Client, c)
}
func (o *Group) GetRecvGroupApplicationList(c *gin.Context) {
func (o *GroupApi) GetRecvGroupApplicationList(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupApplicationList, o.Client, c)
}
func (o *Group) GetUserReqGroupApplicationList(c *gin.Context) {
func (o *GroupApi) GetUserReqGroupApplicationList(c *gin.Context) {
a2r.Call(group.GroupClient.GetUserReqApplicationList, o.Client, c)
}
func (o *Group) GetGroupsInfo(c *gin.Context) {
func (o *GroupApi) GetGroupsInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupsInfo, o.Client, c)
}
func (o *Group) KickGroupMember(c *gin.Context) {
func (o *GroupApi) KickGroupMember(c *gin.Context) {
a2r.Call(group.GroupClient.KickGroupMember, o.Client, c)
}
func (o *Group) GetGroupMembersInfo(c *gin.Context) {
func (o *GroupApi) GetGroupMembersInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupMembersInfo, o.Client, c)
}
func (o *Group) GetGroupMemberList(c *gin.Context) {
func (o *GroupApi) GetGroupMemberList(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupMemberList, o.Client, c)
}
func (o *Group) InviteUserToGroup(c *gin.Context) {
func (o *GroupApi) InviteUserToGroup(c *gin.Context) {
a2r.Call(group.GroupClient.InviteUserToGroup, o.Client, c)
}
func (o *Group) GetJoinedGroupList(c *gin.Context) {
func (o *GroupApi) GetJoinedGroupList(c *gin.Context) {
a2r.Call(group.GroupClient.GetJoinedGroupList, o.Client, c)
}
func (o *Group) DismissGroup(c *gin.Context) {
func (o *GroupApi) DismissGroup(c *gin.Context) {
a2r.Call(group.GroupClient.DismissGroup, o.Client, c)
}
func (o *Group) MuteGroupMember(c *gin.Context) {
func (o *GroupApi) MuteGroupMember(c *gin.Context) {
a2r.Call(group.GroupClient.MuteGroupMember, o.Client, c)
}
func (o *Group) CancelMuteGroupMember(c *gin.Context) {
func (o *GroupApi) CancelMuteGroupMember(c *gin.Context) {
a2r.Call(group.GroupClient.CancelMuteGroupMember, o.Client, c)
}
func (o *Group) MuteGroup(c *gin.Context) {
func (o *GroupApi) MuteGroup(c *gin.Context) {
a2r.Call(group.GroupClient.MuteGroup, o.Client, c)
}
func (o *Group) CancelMuteGroup(c *gin.Context) {
func (o *GroupApi) CancelMuteGroup(c *gin.Context) {
a2r.Call(group.GroupClient.CancelMuteGroup, o.Client, c)
}
func (o *Group) SetGroupMemberInfo(c *gin.Context) {
func (o *GroupApi) SetGroupMemberInfo(c *gin.Context) {
a2r.Call(group.GroupClient.SetGroupMemberInfo, o.Client, c)
}
func (o *Group) GetGroupAbstractInfo(c *gin.Context) {
func (o *GroupApi) GetGroupAbstractInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroupAbstractInfo, o.Client, c)
}
@@ -123,10 +107,10 @@ func (o *Group) GetGroupAbstractInfo(c *gin.Context) {
// a2r.Call(group.GroupClient.GetGroupAllMember, g.userClient, c)
//}
func (o *Group) GetJoinedSuperGroupList(c *gin.Context) {
func (o *GroupApi) GetJoinedSuperGroupList(c *gin.Context) {
a2r.Call(group.GroupClient.GetJoinedSuperGroupList, o.Client, c)
}
func (o *Group) GetSuperGroupsInfo(c *gin.Context) {
func (o *GroupApi) GetSuperGroupsInfo(c *gin.Context) {
a2r.Call(group.GroupClient.GetSuperGroupsInfo, o.Client, c)
}
+31 -46
View File
@@ -1,50 +1,40 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/mitchellh/mapstructure"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
panic(err)
}
client := msg.NewMsgClient(conn)
return &Message{validate: validator.New(), discov: discov, conn: conn, client: client}
}
type Message struct {
conn *grpc.ClientConn
client msg.MsgClient
type MessageApi struct {
rpcclient.Message
validate *validator.Validate
discov discoveryregistry.SvcDiscoveryRegistry
}
func (Message) SetOptions(options map[string]bool, value bool) {
func NewMessageApi(discov discoveryregistry.SvcDiscoveryRegistry) MessageApi {
return MessageApi{Message: *rpcclient.NewMessage(discov), validate: validator.New()}
}
func (MessageApi) SetOptions(options map[string]bool, value bool) {
utils.SetSwitchFromOptions(options, constant.IsHistory, value)
utils.SetSwitchFromOptions(options, constant.IsPersistent, value)
utils.SetSwitchFromOptions(options, constant.IsSenderSync, value)
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, value)
}
func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
var newContent string
var err error
switch params.ContentType {
@@ -109,75 +99,71 @@ func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementS
return &pbData
}
func (m *Message) Client() msg.MsgClient {
return m.client
}
func (m *Message) GetSeq(c *gin.Context) {
func (m *MessageApi) GetSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMaxSeq, m.Client, c)
}
func (m *Message) PullMsgBySeqs(c *gin.Context) {
func (m *MessageApi) PullMsgBySeqs(c *gin.Context) {
a2r.Call(msg.MsgClient.PullMessageBySeqs, m.Client, c)
}
func (m *Message) RevokeMsg(c *gin.Context) {
func (m *MessageApi) RevokeMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.RevokeMsg, m.Client, c)
}
func (m *Message) MarkMsgsAsRead(c *gin.Context) {
func (m *MessageApi) MarkMsgsAsRead(c *gin.Context) {
a2r.Call(msg.MsgClient.MarkMsgsAsRead, m.Client, c)
}
func (m *Message) MarkConversationAsRead(c *gin.Context) {
func (m *MessageApi) MarkConversationAsRead(c *gin.Context) {
a2r.Call(msg.MsgClient.MarkConversationAsRead, m.Client, c)
}
func (m *Message) GetConversationsHasReadAndMaxSeq(c *gin.Context) {
func (m *MessageApi) GetConversationsHasReadAndMaxSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetConversationsHasReadAndMaxSeq, m.Client, c)
}
func (m *Message) SetConversationHasReadSeq(c *gin.Context) {
func (m *MessageApi) SetConversationHasReadSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.SetConversationHasReadSeq, m.Client, c)
}
func (m *Message) ClearConversationsMsg(c *gin.Context) {
func (m *MessageApi) ClearConversationsMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ClearConversationsMsg, m.Client, c)
}
func (m *Message) UserClearAllMsg(c *gin.Context) {
func (m *MessageApi) UserClearAllMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.UserClearAllMsg, m.Client, c)
}
func (m *Message) DeleteMsgs(c *gin.Context) {
func (m *MessageApi) DeleteMsgs(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgs, m.Client, c)
}
func (m *Message) DeleteMsgPhysicalBySeq(c *gin.Context) {
func (m *MessageApi) DeleteMsgPhysicalBySeq(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgPhysicalBySeq, m.Client, c)
}
func (m *Message) DeleteMsgPhysical(c *gin.Context) {
func (m *MessageApi) DeleteMsgPhysical(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgPhysical, m.Client, c)
}
func (m *Message) SetMessageReactionExtensions(c *gin.Context) {
func (m *MessageApi) SetMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, m.Client, c)
}
func (m *Message) GetMessageListReactionExtensions(c *gin.Context) {
func (m *MessageApi) GetMessageListReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, m.Client, c)
}
func (m *Message) AddMessageReactionExtensions(c *gin.Context) {
func (m *MessageApi) AddMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, m.Client, c)
}
func (m *Message) DeleteMessageReactionExtensions(c *gin.Context) {
func (m *MessageApi) DeleteMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, m.Client, c)
}
func (m *Message) SendMessage(c *gin.Context) {
func (m *MessageApi) SendMessage(c *gin.Context) {
params := apistruct.ManagementSendMsgReq{}
if err := c.BindJSON(&params); err != nil {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
@@ -224,16 +210,15 @@ func (m *Message) SendMessage(c *gin.Context) {
return
}
pbReq := m.newUserSendMsgReq(c, &params)
client := msg.NewMsgClient(m.conn)
var status int
respPb, err := client.SendMsg(c, pbReq)
respPb, err := m.Client.SendMsg(c, pbReq)
if err != nil {
status = constant.MsgSendFailed
apiresp.GinError(c, err)
return
}
status = constant.MsgSendSuccessed
_, err = client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
_, err = m.Client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
Status: int32(status),
})
if err != nil {
@@ -242,14 +227,14 @@ func (m *Message) SendMessage(c *gin.Context) {
apiresp.GinSuccess(c, respPb)
}
func (m *Message) ManagementBatchSendMsg(c *gin.Context) {
func (m *MessageApi) ManagementBatchSendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, m.Client, c)
}
func (m *Message) CheckMsgIsSendSuccess(c *gin.Context) {
func (m *MessageApi) CheckMsgIsSendSuccess(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.Client, c)
}
func (m *Message) GetUsersOnlineStatus(c *gin.Context) {
func (m *MessageApi) GetUsersOnlineStatus(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.Client, c)
}
+9 -9
View File
@@ -37,7 +37,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
}
userRouterGroup := r.Group("/user")
{
u := NewUser(discov)
u := NewUserApi(discov)
userRouterGroupChild := mw.NewRouterGroup(userRouterGroup, "")
userRouterGroupChildToken := mw.NewRouterGroup(userRouterGroup, "", mw.WithGinParseToken(rdb))
userRouterGroupChild.POST("/user_register", u.UserRegister)
@@ -52,7 +52,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
//friend routing group
friendRouterGroup := r.Group("/friend")
{
f := NewFriend(discov)
f := NewFriendApi(discov)
friendRouterGroup.Use(mw.GinParseToken(rdb))
friendRouterGroup.POST("/delete_friend", f.DeleteFriend) //1
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList) //1
@@ -67,7 +67,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
friendRouterGroup.POST("/import_friend", f.ImportFriends) //1
friendRouterGroup.POST("/is_friend", f.IsFriend) //1
}
g := NewGroup(discov)
g := NewGroupApi(discov)
groupRouterGroup := r.Group("/group")
{
@@ -105,8 +105,8 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
////certificate
authRouterGroup := r.Group("/auth")
{
a := NewAuth(discov)
u := NewUser(discov)
a := NewAuthApi(discov)
u := NewUserApi(discov)
authRouterGroupChild := mw.NewRouterGroup(authRouterGroup, "")
authRouterGroupChildToken := mw.NewRouterGroup(authRouterGroup, "", mw.WithGinParseToken(rdb))
authRouterGroupChild.POST("/user_register", u.UserRegister) //1
@@ -117,7 +117,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
////Third service
thirdGroup := r.Group("/third")
{
t := NewThird(discov)
t := NewThirdApi(discov)
thirdGroup.Use(mw.GinParseToken(rdb))
thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken)
thirdGroup.POST("/set_app_badge", t.SetAppBadge)
@@ -132,7 +132,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
////Message
msgGroup := r.Group("/msg")
{
m := NewMsg(discov)
m := NewMessageApi(discov)
msgGroup.Use(mw.GinParseToken(rdb))
msgGroup.POST("/newest_seq", m.GetSeq)
msgGroup.POST("/send_msg", m.SendMessage)
@@ -160,7 +160,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
////Conversation
conversationGroup := r.Group("/conversation")
{
c := NewConversation(discov)
c := NewConversationApi(discov)
conversationGroup.Use(mw.GinParseToken(rdb))
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
conversationGroup.POST("/get_conversation", c.GetConversation)
@@ -174,7 +174,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
statisticsGroup := r.Group("/statistics")
{
s := NewStatistics(discov)
s := NewStatisticsApi(discov)
conversationGroup.Use(mw.GinParseToken(rdb))
statisticsGroup.POST("/user_register", s.UserRegister)
}
+6 -22
View File
@@ -1,35 +1,19 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewStatistics(discov discoveryregistry.SvcDiscoveryRegistry) *Statistics {
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 StatisticsApi rpcclient.User
func NewStatisticsApi(discov discoveryregistry.SvcDiscoveryRegistry) StatisticsApi {
return StatisticsApi(*rpcclient.NewUser(discov))
}
type Statistics struct {
conn *grpc.ClientConn
client user.UserClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func (s *Statistics) Client() user.UserClient {
return s.client
}
func (s *Statistics) UserRegister(c *gin.Context) {
func (s *StatisticsApi) UserRegister(c *gin.Context) {
a2r.Call(user.UserClient.UserRegisterCount, s.Client, c)
}
+13 -28
View File
@@ -1,66 +1,51 @@
package api
import (
"context"
"math/rand"
"net/http"
"strconv"
"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/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
panic(err)
}
client := third.NewThirdClient(conn)
return &Third{discov: discov, client: client, conn: conn}
type ThirdApi rpcclient.Third
func NewThirdApi(discov discoveryregistry.SvcDiscoveryRegistry) ThirdApi {
return ThirdApi(*rpcclient.NewThird(discov))
}
type Third struct {
conn *grpc.ClientConn
client third.ThirdClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Third) Client() third.ThirdClient {
return o.client
}
func (o *Third) ApplyPut(c *gin.Context) {
func (o *ThirdApi) ApplyPut(c *gin.Context) {
a2r.Call(third.ThirdClient.ApplyPut, o.Client, c)
}
func (o *Third) GetPut(c *gin.Context) {
func (o *ThirdApi) GetPut(c *gin.Context) {
a2r.Call(third.ThirdClient.GetPut, o.Client, c)
}
func (o *Third) ConfirmPut(c *gin.Context) {
func (o *ThirdApi) ConfirmPut(c *gin.Context) {
a2r.Call(third.ThirdClient.ConfirmPut, o.Client, c)
}
func (o *Third) GetHash(c *gin.Context) {
func (o *ThirdApi) GetHash(c *gin.Context) {
a2r.Call(third.ThirdClient.GetHashInfo, o.Client, c)
}
func (o *Third) FcmUpdateToken(c *gin.Context) {
func (o *ThirdApi) FcmUpdateToken(c *gin.Context) {
a2r.Call(third.ThirdClient.FcmUpdateToken, o.Client, c)
}
func (o *Third) SetAppBadge(c *gin.Context) {
func (o *ThirdApi) SetAppBadge(c *gin.Context) {
a2r.Call(third.ThirdClient.SetAppBadge, o.Client, c)
}
func (o *Third) GetURL(c *gin.Context) {
func (o *ThirdApi) GetURL(c *gin.Context) {
if c.Request.Method == http.MethodPost {
a2r.Call(third.ThirdClient.GetUrl, o.Client, c)
return
@@ -80,7 +65,7 @@ func (o *Third) GetURL(c *gin.Context) {
}
attachment, _ := strconv.ParseBool(c.Query("attachment"))
c.Set(constant.OperationID, operationID)
resp, err := o.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 errs.ErrArgs.Is(err) {
c.String(http.StatusBadRequest, err.Error())
+13 -29
View File
@@ -1,68 +1,52 @@
package api
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
if err != nil {
panic(err)
}
client := user.NewUserClient(conn)
return &User{discov: discov, client: client, conn: conn}
type UserApi rpcclient.User
func NewUserApi(discov discoveryregistry.SvcDiscoveryRegistry) UserApi {
return UserApi(*rpcclient.NewUser(discov))
}
type User struct {
conn *grpc.ClientConn
client user.UserClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func (s *User) Client() user.UserClient {
return s.client
}
func (u *User) UserRegister(c *gin.Context) {
func (u *UserApi) UserRegister(c *gin.Context) {
a2r.Call(user.UserClient.UserRegister, u.Client, c)
}
func (u *User) UpdateUserInfo(c *gin.Context) {
func (u *UserApi) UpdateUserInfo(c *gin.Context) {
a2r.Call(user.UserClient.UpdateUserInfo, u.Client, c)
}
func (u *User) SetGlobalRecvMessageOpt(c *gin.Context) {
func (u *UserApi) SetGlobalRecvMessageOpt(c *gin.Context) {
a2r.Call(user.UserClient.SetGlobalRecvMessageOpt, u.Client, c)
}
func (u *User) GetUsersPublicInfo(c *gin.Context) {
func (u *UserApi) GetUsersPublicInfo(c *gin.Context) {
a2r.Call(user.UserClient.GetDesignateUsers, u.Client, c)
}
func (u *User) GetAllUsersID(c *gin.Context) {
func (u *UserApi) GetAllUsersID(c *gin.Context) {
a2r.Call(user.UserClient.GetDesignateUsers, u.Client, c)
}
func (u *User) AccountCheck(c *gin.Context) {
func (u *UserApi) AccountCheck(c *gin.Context) {
a2r.Call(user.UserClient.AccountCheck, u.Client, c)
}
func (u *User) GetUsers(c *gin.Context) {
func (u *UserApi) GetUsers(c *gin.Context) {
a2r.Call(user.UserClient.GetPaginationUsers, u.Client, c)
}
func (u *User) GetUsersOnlineStatus(c *gin.Context) {
func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
params := apistruct.ManagementSendMsgReq{}
if err := c.BindJSON(&params); err != nil {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())