2021-05-26 19:15:25 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2022-06-24 17:45:33 +08:00
|
|
|
_ "Open_IM/cmd/open_im_api/docs"
|
2021-10-11 21:36:28 +08:00
|
|
|
apiAuth "Open_IM/internal/api/auth"
|
2021-12-07 14:28:07 +08:00
|
|
|
"Open_IM/internal/api/conversation"
|
2021-10-11 21:36:28 +08:00
|
|
|
"Open_IM/internal/api/friend"
|
|
|
|
|
"Open_IM/internal/api/group"
|
|
|
|
|
"Open_IM/internal/api/manage"
|
2022-07-20 21:26:52 +08:00
|
|
|
apiChat "Open_IM/internal/api/msg"
|
2022-03-25 18:46:27 +08:00
|
|
|
"Open_IM/internal/api/office"
|
2022-04-15 19:48:17 +08:00
|
|
|
"Open_IM/internal/api/organization"
|
2021-10-11 21:36:28 +08:00
|
|
|
apiThird "Open_IM/internal/api/third"
|
|
|
|
|
"Open_IM/internal/api/user"
|
2022-04-05 16:41:37 +08:00
|
|
|
"Open_IM/pkg/common/config"
|
2021-10-11 22:50:24 +08:00
|
|
|
"Open_IM/pkg/common/log"
|
2021-10-11 22:12:01 +08:00
|
|
|
"Open_IM/pkg/utils"
|
2021-05-26 19:15:25 +08:00
|
|
|
"flag"
|
2022-04-06 15:33:16 +08:00
|
|
|
"fmt"
|
2022-06-24 17:45:33 +08:00
|
|
|
//_ "github.com/razeencheng/demo-go/swaggo-gin/docs"
|
|
|
|
|
swaggerFiles "github.com/swaggo/files"
|
|
|
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
2022-04-05 15:07:34 +08:00
|
|
|
"io"
|
|
|
|
|
"os"
|
2021-05-26 19:15:25 +08:00
|
|
|
"strconv"
|
2021-12-17 10:49:01 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2021-07-15 11:23:20 +08:00
|
|
|
//"syscall"
|
2022-04-05 19:31:35 +08:00
|
|
|
"Open_IM/pkg/common/constant"
|
2021-05-26 19:15:25 +08:00
|
|
|
)
|
|
|
|
|
|
2022-06-29 18:48:17 +08:00
|
|
|
// @title open-IM-Server API
|
|
|
|
|
// @version 1.0
|
|
|
|
|
// @description open-IM-Server 的API服务器文档, 文档中所有请求都有一个operationID字段用于链路追踪
|
|
|
|
|
|
|
|
|
|
// @license.name Apache 2.0
|
|
|
|
|
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
|
// @BasePath /
|
2021-05-26 19:15:25 +08:00
|
|
|
func main() {
|
2022-04-05 19:31:35 +08:00
|
|
|
log.NewPrivateLog(constant.LogFileName)
|
2022-01-14 09:51:43 +08:00
|
|
|
gin.SetMode(gin.ReleaseMode)
|
2022-04-05 15:07:34 +08:00
|
|
|
f, _ := os.Create("../logs/api.log")
|
|
|
|
|
gin.DefaultWriter = io.MultiWriter(f)
|
2022-04-29 17:59:42 +08:00
|
|
|
gin.SetMode(gin.DebugMode)
|
2021-05-26 19:15:25 +08:00
|
|
|
r := gin.Default()
|
|
|
|
|
r.Use(utils.CorsHandler())
|
2022-04-05 16:41:37 +08:00
|
|
|
|
2022-04-26 09:09:33 +08:00
|
|
|
log.Info("load config: ", config.Config)
|
2022-06-24 17:45:33 +08:00
|
|
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
2021-05-26 19:15:25 +08:00
|
|
|
// user routing group, which handles user registration and login services
|
|
|
|
|
userRouterGroup := r.Group("/user")
|
|
|
|
|
{
|
2022-06-16 19:33:35 +08:00
|
|
|
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
|
|
|
|
|
userRouterGroup.POST("/set_global_msg_recv_opt", user.SetGlobalRecvMessageOpt)
|
2022-04-18 14:27:12 +08:00
|
|
|
userRouterGroup.POST("/get_users_info", user.GetUsersInfo) //1
|
|
|
|
|
userRouterGroup.POST("/get_self_user_info", user.GetSelfUserInfo) //1
|
|
|
|
|
userRouterGroup.POST("/get_users_online_status", user.GetUsersOnlineStatus) //1
|
2022-04-22 18:56:39 +08:00
|
|
|
userRouterGroup.POST("/get_users_info_from_cache", user.GetUsersInfoFromCache)
|
2022-04-28 15:13:39 +08:00
|
|
|
userRouterGroup.POST("/get_user_friend_from_cache", user.GetFriendIDListFromCache)
|
|
|
|
|
userRouterGroup.POST("/get_black_list_from_cache", user.GetBlackIDListFromCache)
|
2022-06-27 11:32:43 +08:00
|
|
|
userRouterGroup.POST("/get_all_users_uid", manage.GetAllUsersUid) //1
|
|
|
|
|
userRouterGroup.POST("/account_check", manage.AccountCheck) //1
|
|
|
|
|
// userRouterGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus) //1
|
2021-05-26 19:15:25 +08:00
|
|
|
}
|
|
|
|
|
//friend routing group
|
|
|
|
|
friendRouterGroup := r.Group("/friend")
|
|
|
|
|
{
|
2021-12-28 15:33:47 +08:00
|
|
|
// friendRouterGroup.POST("/get_friends_info", friend.GetFriendsInfo)
|
2022-01-15 15:30:48 +08:00
|
|
|
friendRouterGroup.POST("/add_friend", friend.AddFriend) //1
|
|
|
|
|
friendRouterGroup.POST("/delete_friend", friend.DeleteFriend) //1
|
|
|
|
|
friendRouterGroup.POST("/get_friend_apply_list", friend.GetFriendApplyList) //1
|
|
|
|
|
friendRouterGroup.POST("/get_self_friend_apply_list", friend.GetSelfFriendApplyList) //1
|
|
|
|
|
friendRouterGroup.POST("/get_friend_list", friend.GetFriendList) //1
|
|
|
|
|
friendRouterGroup.POST("/add_friend_response", friend.AddFriendResponse) //1
|
|
|
|
|
friendRouterGroup.POST("/set_friend_remark", friend.SetFriendRemark) //1
|
2022-01-15 15:25:12 +08:00
|
|
|
|
|
|
|
|
friendRouterGroup.POST("/add_black", friend.AddBlack) //1
|
|
|
|
|
friendRouterGroup.POST("/get_black_list", friend.GetBlacklist) //1
|
|
|
|
|
friendRouterGroup.POST("/remove_black", friend.RemoveBlack) //1
|
|
|
|
|
|
|
|
|
|
friendRouterGroup.POST("/import_friend", friend.ImportFriend) //1
|
|
|
|
|
friendRouterGroup.POST("/is_friend", friend.IsFriend) //1
|
2021-05-26 19:15:25 +08:00
|
|
|
}
|
|
|
|
|
//group related routing group
|
2021-06-28 15:28:07 +08:00
|
|
|
groupRouterGroup := r.Group("/group")
|
2021-05-26 19:15:25 +08:00
|
|
|
{
|
2022-01-19 17:17:51 +08:00
|
|
|
groupRouterGroup.POST("/create_group", group.CreateGroup) //1
|
|
|
|
|
groupRouterGroup.POST("/set_group_info", group.SetGroupInfo) //1
|
2022-05-30 11:55:27 +08:00
|
|
|
groupRouterGroup.POST("/join_group", group.JoinGroup) //1
|
2022-01-19 17:17:51 +08:00
|
|
|
groupRouterGroup.POST("/quit_group", group.QuitGroup) //1
|
|
|
|
|
groupRouterGroup.POST("/group_application_response", group.ApplicationGroupResponse) //1
|
|
|
|
|
groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner) //1
|
|
|
|
|
groupRouterGroup.POST("/get_recv_group_applicationList", group.GetRecvGroupApplicationList) //1
|
2022-02-09 19:19:22 +08:00
|
|
|
groupRouterGroup.POST("/get_user_req_group_applicationList", group.GetUserReqGroupApplicationList)
|
2022-03-21 11:13:17 +08:00
|
|
|
groupRouterGroup.POST("/get_groups_info", group.GetGroupsInfo) //1
|
|
|
|
|
groupRouterGroup.POST("/kick_group", group.KickGroupMember) //1
|
|
|
|
|
groupRouterGroup.POST("/get_group_member_list", group.GetGroupMemberList) //no use
|
|
|
|
|
groupRouterGroup.POST("/get_group_all_member_list", group.GetGroupAllMemberList) //1
|
|
|
|
|
groupRouterGroup.POST("/get_group_members_info", group.GetGroupMembersInfo) //1
|
|
|
|
|
groupRouterGroup.POST("/invite_user_to_group", group.InviteUserToGroup) //1
|
2022-05-30 11:55:27 +08:00
|
|
|
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList)
|
|
|
|
|
groupRouterGroup.POST("/dismiss_group", group.DismissGroup) //
|
2022-03-29 11:48:17 +08:00
|
|
|
groupRouterGroup.POST("/mute_group_member", group.MuteGroupMember)
|
|
|
|
|
groupRouterGroup.POST("/cancel_mute_group_member", group.CancelMuteGroupMember) //MuteGroup
|
|
|
|
|
groupRouterGroup.POST("/mute_group", group.MuteGroup)
|
|
|
|
|
groupRouterGroup.POST("/cancel_mute_group", group.CancelMuteGroup)
|
2022-04-18 11:52:17 +08:00
|
|
|
groupRouterGroup.POST("/set_group_member_nickname", group.SetGroupMemberNickname)
|
2022-06-02 18:17:11 +08:00
|
|
|
groupRouterGroup.POST("/set_group_member_info", group.SetGroupMemberInfo)
|
2022-08-04 14:04:29 +08:00
|
|
|
groupRouterGroup.POST("/get_group_all_member_list_by_split", group.GetGroupAllMemberListBySplit)
|
2022-05-30 11:55:27 +08:00
|
|
|
}
|
|
|
|
|
superGroupRouterGroup := r.Group("/super_group")
|
|
|
|
|
{
|
2022-05-30 17:12:08 +08:00
|
|
|
superGroupRouterGroup.POST("/get_joined_group_list", group.GetJoinedSuperGroupList)
|
|
|
|
|
superGroupRouterGroup.POST("/get_groups_info", group.GetSuperGroupsInfo)
|
2021-06-28 15:28:07 +08:00
|
|
|
}
|
2021-05-26 19:15:25 +08:00
|
|
|
//certificate
|
|
|
|
|
authRouterGroup := r.Group("/auth")
|
|
|
|
|
{
|
2021-12-29 15:50:50 +08:00
|
|
|
authRouterGroup.POST("/user_register", apiAuth.UserRegister) //1
|
2021-12-29 17:26:06 +08:00
|
|
|
authRouterGroup.POST("/user_token", apiAuth.UserToken) //1
|
2022-05-10 10:12:53 +08:00
|
|
|
authRouterGroup.POST("/parse_token", apiAuth.ParseToken) //1
|
2022-06-07 10:13:19 +08:00
|
|
|
authRouterGroup.POST("/force_logout", apiAuth.ForceLogout) //1
|
2021-05-26 19:15:25 +08:00
|
|
|
}
|
|
|
|
|
//Third service
|
|
|
|
|
thirdGroup := r.Group("/third")
|
|
|
|
|
{
|
|
|
|
|
thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential)
|
2022-03-21 11:13:17 +08:00
|
|
|
thirdGroup.POST("/ali_oss_credential", apiThird.AliOSSCredential)
|
2022-02-18 17:06:27 +08:00
|
|
|
thirdGroup.POST("/minio_storage_credential", apiThird.MinioStorageCredential)
|
2022-03-23 15:44:34 +08:00
|
|
|
thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile)
|
2022-05-10 16:53:58 +08:00
|
|
|
thirdGroup.POST("/upload_update_app", apiThird.UploadUpdateApp)
|
|
|
|
|
thirdGroup.POST("/get_download_url", apiThird.GetDownloadURL)
|
2022-06-02 18:17:11 +08:00
|
|
|
thirdGroup.POST("/get_rtc_invitation_info", apiThird.GetRTCInvitationInfo)
|
2022-06-06 18:15:32 +08:00
|
|
|
thirdGroup.POST("/get_rtc_invitation_start_app", apiThird.GetRTCInvitationInfoStartApp)
|
2022-07-25 17:07:47 +08:00
|
|
|
thirdGroup.POST("/fcm_update_token", apiThird.FcmUpdateToken)
|
2021-05-26 19:15:25 +08:00
|
|
|
}
|
|
|
|
|
//Message
|
2021-12-23 17:34:32 +08:00
|
|
|
chatGroup := r.Group("/msg")
|
2021-05-26 19:15:25 +08:00
|
|
|
{
|
2021-12-23 19:37:41 +08:00
|
|
|
chatGroup.POST("/newest_seq", apiChat.GetSeq)
|
|
|
|
|
chatGroup.POST("/send_msg", apiChat.SendMsg)
|
|
|
|
|
chatGroup.POST("/pull_msg_by_seq", apiChat.PullMsgBySeqList)
|
2022-03-17 19:00:05 +08:00
|
|
|
chatGroup.POST("/del_msg", apiChat.DelMsg)
|
2022-07-12 16:16:04 +08:00
|
|
|
chatGroup.POST("/del_super_group_msg", apiChat.DelSuperGroupMsg)
|
2022-06-01 15:09:20 +08:00
|
|
|
chatGroup.POST("/clear_msg", apiChat.ClearMsg)
|
2022-06-27 13:31:37 +08:00
|
|
|
chatGroup.POST("/manage_send_msg", manage.ManagementSendMsg)
|
2022-06-27 11:32:43 +08:00
|
|
|
chatGroup.POST("/batch_send_msg", manage.ManagementBatchSendMsg)
|
2022-07-26 15:16:46 +08:00
|
|
|
chatGroup.POST("/check_msg_is_send_success", manage.CheckMsgIsSendSuccess)
|
2022-07-20 20:59:52 +08:00
|
|
|
chatGroup.POST("/set_msg_min_seq", apiChat.SetMsgMinSeq)
|
2021-05-26 19:15:25 +08:00
|
|
|
}
|
2021-11-29 17:22:23 +08:00
|
|
|
//Conversation
|
|
|
|
|
conversationGroup := r.Group("/conversation")
|
2022-03-16 18:02:26 +08:00
|
|
|
{ //1
|
2022-03-11 17:37:01 +08:00
|
|
|
conversationGroup.POST("/get_all_conversations", conversation.GetAllConversations)
|
|
|
|
|
conversationGroup.POST("/get_conversation", conversation.GetConversation)
|
|
|
|
|
conversationGroup.POST("/get_conversations", conversation.GetConversations)
|
|
|
|
|
conversationGroup.POST("/set_conversation", conversation.SetConversation)
|
|
|
|
|
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
2022-03-16 18:02:26 +08:00
|
|
|
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
2022-04-24 16:55:47 +08:00
|
|
|
conversationGroup.POST("/modify_conversation_field", conversation.ModifyConversationField)
|
2022-03-25 18:46:27 +08:00
|
|
|
}
|
|
|
|
|
// office
|
|
|
|
|
officeGroup := r.Group("/office")
|
2021-11-29 17:22:23 +08:00
|
|
|
{
|
2022-03-25 18:46:27 +08:00
|
|
|
officeGroup.POST("/get_user_tags", office.GetUserTags)
|
2022-03-31 14:50:02 +08:00
|
|
|
officeGroup.POST("/get_user_tag_by_id", office.GetUserTagByID)
|
2022-03-25 18:46:27 +08:00
|
|
|
officeGroup.POST("/create_tag", office.CreateTag)
|
|
|
|
|
officeGroup.POST("/delete_tag", office.DeleteTag)
|
|
|
|
|
officeGroup.POST("/set_tag", office.SetTag)
|
|
|
|
|
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
|
2022-03-28 12:17:07 +08:00
|
|
|
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
|
2022-04-15 12:03:23 +08:00
|
|
|
|
|
|
|
|
officeGroup.POST("/create_one_work_moment", office.CreateOneWorkMoment)
|
|
|
|
|
officeGroup.POST("/delete_one_work_moment", office.DeleteOneWorkMoment)
|
|
|
|
|
officeGroup.POST("/like_one_work_moment", office.LikeOneWorkMoment)
|
|
|
|
|
officeGroup.POST("/comment_one_work_moment", office.CommentOneWorkMoment)
|
2022-04-18 19:24:36 +08:00
|
|
|
officeGroup.POST("/get_work_moment_by_id", office.GetWorkMomentByID)
|
2022-04-15 12:03:23 +08:00
|
|
|
officeGroup.POST("/get_user_work_moments", office.GetUserWorkMoments)
|
|
|
|
|
officeGroup.POST("/get_user_friend_work_moments", office.GetUserFriendWorkMoments)
|
|
|
|
|
officeGroup.POST("/set_user_work_moments_level", office.SetUserWorkMomentsLevel)
|
2022-05-05 11:58:48 +08:00
|
|
|
officeGroup.POST("/delete_comment", office.DeleteComment)
|
2021-11-29 17:22:23 +08:00
|
|
|
}
|
2022-04-15 19:48:17 +08:00
|
|
|
|
|
|
|
|
organizationGroup := r.Group("/organization")
|
|
|
|
|
{
|
|
|
|
|
organizationGroup.POST("/create_department", organization.CreateDepartment)
|
|
|
|
|
organizationGroup.POST("/update_department", organization.UpdateDepartment)
|
2022-04-17 11:59:31 +08:00
|
|
|
organizationGroup.POST("/get_sub_department", organization.GetSubDepartment)
|
2022-04-15 19:48:17 +08:00
|
|
|
organizationGroup.POST("/delete_department", organization.DeleteDepartment)
|
2022-04-19 16:40:57 +08:00
|
|
|
organizationGroup.POST("/get_all_department", organization.GetAllDepartment)
|
2022-04-17 14:39:48 +08:00
|
|
|
|
2022-04-15 19:48:17 +08:00
|
|
|
organizationGroup.POST("/create_organization_user", organization.CreateOrganizationUser)
|
|
|
|
|
organizationGroup.POST("/update_organization_user", organization.UpdateOrganizationUser)
|
2022-04-18 10:53:23 +08:00
|
|
|
organizationGroup.POST("/delete_organization_user", organization.DeleteOrganizationUser)
|
2022-04-17 14:39:48 +08:00
|
|
|
|
2022-04-18 10:53:23 +08:00
|
|
|
organizationGroup.POST("/create_department_member", organization.CreateDepartmentMember)
|
2022-04-15 19:48:17 +08:00
|
|
|
organizationGroup.POST("/get_user_in_department", organization.GetUserInDepartment)
|
2022-04-18 16:18:10 +08:00
|
|
|
organizationGroup.POST("/update_user_in_department", organization.UpdateUserInDepartment)
|
2022-04-18 10:53:23 +08:00
|
|
|
|
2022-04-15 19:48:17 +08:00
|
|
|
organizationGroup.POST("/get_department_member", organization.GetDepartmentMember)
|
2022-04-16 20:10:10 +08:00
|
|
|
organizationGroup.POST("/delete_user_in_department", organization.DeleteUserInDepartment)
|
2022-04-19 16:40:57 +08:00
|
|
|
|
2022-04-15 19:48:17 +08:00
|
|
|
}
|
|
|
|
|
|
2022-04-05 20:06:08 +08:00
|
|
|
go apiThird.MinioInit()
|
2022-05-19 10:44:39 +08:00
|
|
|
defaultPorts := config.Config.Api.GinPort
|
|
|
|
|
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10002 as port")
|
2021-05-26 19:15:25 +08:00
|
|
|
flag.Parse()
|
2022-05-07 19:52:18 +08:00
|
|
|
address := "0.0.0.0:" + strconv.Itoa(*ginPort)
|
|
|
|
|
if config.Config.Api.ListenIP != "" {
|
|
|
|
|
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
|
|
|
|
|
}
|
|
|
|
|
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
|
|
|
|
|
fmt.Println("start api server, address: ", address)
|
|
|
|
|
err := r.Run(address)
|
2022-04-06 15:33:16 +08:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error("", "run failed ", *ginPort, err.Error())
|
|
|
|
|
}
|
2021-05-26 19:15:25 +08:00
|
|
|
}
|