You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/api/route.go

175 lines
8.4 KiB

2 years ago
package api
import (
2 years ago
"context"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
2 years ago
"github.com/gin-gonic/gin"
2 years ago
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
2 years ago
"github.com/go-redis/redis/v8"
2 years ago
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
2 years ago
)
func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.UniversalClient) *gin.Engine {
zk.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) // 默认RPC中间件
2 years ago
gin.SetMode(gin.ReleaseMode)
//f, _ := os.Create("../logs/api.log")
//gin.DefaultWriter = io.MultiWriter(f)
//gin.SetMode(gin.DebugMode)
2 years ago
r := gin.New()
2 years ago
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
_ = v.RegisterValidation("required_if", RequiredIf)
}
2 years ago
log.ZInfo(context.Background(), "load config", "config", config.Config)
r.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID())
2 years ago
if config.Config.Prometheus.Enable {
prome.NewApiRequestCounter()
prome.NewApiRequestFailedCounter()
prome.NewApiRequestSuccessCounter()
2 years ago
r.Use(prome.PrometheusMiddleware)
2 years ago
r.GET("/metrics", prome.PrometheusHandler())
}
userRouterGroup := r.Group("/user")
{
2 years ago
u := NewUser(zk)
2 years ago
userRouterGroupChild := mw.NewRouterGroup(userRouterGroup, "")
2 years ago
userRouterGroupChildToken := mw.NewRouterGroup(userRouterGroup, "", mw.WithGinParseToken(rdb))
userRouterGroupChild.POST("/user_register", u.UserRegister)
userRouterGroupChildToken.POST("/update_user_info", u.UpdateUserInfo) //1
userRouterGroupChildToken.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
userRouterGroupChildToken.POST("/get_users_info", u.GetUsersPublicInfo) //1
userRouterGroupChildToken.POST("/get_all_users_uid", u.GetAllUsersID) // todo
userRouterGroupChildToken.POST("/account_check", u.AccountCheck) // todo
userRouterGroupChildToken.POST("/get_users", u.GetUsers)
2 years ago
userRouterGroupChildToken.POST("/get_users_online_status", u.GetUsersOnlineStatus)
2 years ago
}
2 years ago
//friend routing group
2 years ago
friendRouterGroup := r.Group("/friend")
{
2 years ago
f := NewFriend(zk)
2 years ago
friendRouterGroup.Use(mw.GinParseToken(rdb))
2 years ago
friendRouterGroup.POST("/delete_friend", f.DeleteFriend) //1
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList) //1
friendRouterGroup.POST("/get_self_friend_apply_list", f.GetSelfApplyList) //1
friendRouterGroup.POST("/get_friend_list", f.GetFriendList) //1
2 years ago
friendRouterGroup.POST("/add_friend", f.ApplyToAddFriend) //1
2 years ago
friendRouterGroup.POST("/add_friend_response", f.RespondFriendApply) //1
2 years ago
friendRouterGroup.POST("/set_friend_remark", f.SetFriendRemark) //1
friendRouterGroup.POST("/add_black", f.AddBlack) //1
2 years ago
friendRouterGroup.POST("/get_black_list", f.GetPaginationBlacks) //1
friendRouterGroup.POST("/remove_black", f.RemoveBlack) //1
friendRouterGroup.POST("/import_friend", f.ImportFriends) //1
2 years ago
friendRouterGroup.POST("/is_friend", f.IsFriend) //1
2 years ago
}
2 years ago
g := NewGroup(zk)
2 years ago
groupRouterGroup := r.Group("/group")
{
2 years ago
2 years ago
groupRouterGroup.Use(mw.GinParseToken(rdb))
2 years ago
groupRouterGroup.POST("/create_group", g.NewCreateGroup) //1
groupRouterGroup.POST("/set_group_info", g.NewSetGroupInfo) //1
groupRouterGroup.POST("/join_group", g.JoinGroup) //1
groupRouterGroup.POST("/quit_group", g.QuitGroup) //1
groupRouterGroup.POST("/group_application_response", g.ApplicationGroupResponse) //1
groupRouterGroup.POST("/transfer_group", g.TransferGroupOwner) //1
groupRouterGroup.POST("/get_recv_group_applicationList", g.GetRecvGroupApplicationList) //1
groupRouterGroup.POST("/get_user_req_group_applicationList", g.GetUserReqGroupApplicationList)
groupRouterGroup.POST("/get_groups_info", g.GetGroupsInfo) //1
groupRouterGroup.POST("/kick_group", g.KickGroupMember) //1
2 years ago
// groupRouterGroup.POST("/get_group_all_member_list", g.GetGroupAllMemberList) //1
2 years ago
groupRouterGroup.POST("/get_group_members_info", g.GetGroupMembersInfo) //1
2 years ago
groupRouterGroup.POST("/get_group_member_list", g.GetGroupMemberList) //1
2 years ago
groupRouterGroup.POST("/invite_user_to_group", g.InviteUserToGroup) //1
2 years ago
groupRouterGroup.POST("/get_joined_group_list", g.GetJoinedGroupList)
groupRouterGroup.POST("/dismiss_group", g.DismissGroup) //
groupRouterGroup.POST("/mute_group_member", g.MuteGroupMember)
groupRouterGroup.POST("/cancel_mute_group_member", g.CancelMuteGroupMember) //MuteGroup
groupRouterGroup.POST("/mute_group", g.MuteGroup)
groupRouterGroup.POST("/cancel_mute_group", g.CancelMuteGroup)
2 years ago
//groupRouterGroup.POST("/set_group_member_nickname", g.SetGroupMemberNickname)
2 years ago
groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo)
groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo)
2 years ago
}
superGroupRouterGroup := r.Group("/super_group")
{
2 years ago
superGroupRouterGroup.Use(mw.GinParseToken(rdb))
2 years ago
superGroupRouterGroup.POST("/get_joined_group_list", g.GetJoinedSuperGroupList)
superGroupRouterGroup.POST("/get_groups_info", g.GetSuperGroupsInfo)
2 years ago
}
////certificate
authRouterGroup := r.Group("/auth")
{
2 years ago
a := NewAuth(zk)
u := NewUser(zk)
2 years ago
authRouterGroupChild := mw.NewRouterGroup(authRouterGroup, "")
2 years ago
authRouterGroupChildToken := mw.NewRouterGroup(authRouterGroup, "", mw.WithGinParseToken(rdb))
2 years ago
authRouterGroupChild.POST("/user_register", u.UserRegister) //1
authRouterGroupChild.POST("/user_token", a.UserToken) //1
authRouterGroupChildToken.POST("/parse_token", a.ParseToken) //1
authRouterGroupChildToken.POST("/force_logout", a.ForceLogout) //1
2 years ago
}
////Third service
thirdGroup := r.Group("/third")
{
2 years ago
t := NewThird(zk)
2 years ago
thirdGroup.Use(mw.GinParseToken(rdb))
2 years ago
thirdGroup.POST("/get_rtc_invitation_info", t.GetSignalInvitationInfo)
thirdGroup.POST("/get_rtc_invitation_start_app", t.GetSignalInvitationInfoStartApp)
thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken)
thirdGroup.POST("/set_app_badge", t.SetAppBadge)
thirdGroup.POST("/apply_put", t.ApplyPut)
thirdGroup.POST("/get_put", t.GetPut)
thirdGroup.POST("/confirm_put", t.ConfirmPut)
2 years ago
thirdGroup.POST("/get_hash", t.GetHash)
2 years ago
thirdGroup.POST("/object", t.GetURL)
2 years ago
thirdGroup.GET("/object", t.GetURL)
2 years ago
}
////Message
2 years ago
msgGroup := r.Group("/msg")
2 years ago
{
2 years ago
m := NewMsg(zk)
2 years ago
msgGroup.Use(mw.GinParseToken(rdb))
msgGroup.POST("/newest_seq", m.GetSeq)
2 years ago
msgGroup.POST("/send_msg", m.SendMessage)
2 years ago
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
2 years ago
msgGroup.POST("/revoke_msg", m.RevokeMsg)
2 years ago
2 years ago
msgGroup.POST("/clear_conversation_msg", m.ClearConversationsMsg)
msgGroup.POST("/user_clear_all_msg", m.UserClearAllMsg)
msgGroup.POST("/delete_msgs", m.DeleteMsgs)
msgGroup.POST("/delete_msg_phsical_by_seq", m.DeleteMsgPhysicalBySeq)
msgGroup.POST("/delete_msg_physical", m.DeleteMsgPhysical)
2 years ago
msgGroup.POST("/batch_send_msg", m.ManagementBatchSendMsg)
msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
2 years ago
2 years ago
//msgGroup.POST("/set_message_reaction_extensions", msg.SetMessageReactionExtensions)
//msgGroup.POST("/get_message_list_reaction_extensions", msg.GetMessageListReactionExtensions)
//msgGroup.POST("/add_message_reaction_extensions", msg.AddMessageReactionExtensions)
//msgGroup.POST("/delete_message_reaction_extensions", msg.DeleteMessageReactionExtensions)
2 years ago
}
////Conversation
conversationGroup := r.Group("/conversation")
{
2 years ago
c := NewConversation(zk)
2 years ago
conversationGroup.Use(mw.GinParseToken(rdb))
2 years ago
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
conversationGroup.POST("/get_conversation", c.GetConversation)
conversationGroup.POST("/get_conversations", c.GetConversations)
conversationGroup.POST("/set_conversation", c.SetConversation)
conversationGroup.POST("/batch_set_conversation", c.BatchSetConversations)
conversationGroup.POST("/set_recv_msg_opt", c.SetRecvMsgOpt)
conversationGroup.POST("/modify_conversation_field", c.ModifyConversationField)
2 years ago
conversationGroup.POST("/get_conversations_has_read_and_max_seq", c.GetConversationsHasReadAndMaxSeq)
2 years ago
conversationGroup.POST("/set_conversations", c.SetConversations)
2 years ago
}
return r
}