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/cmd/open_im_api/main.go

259 lines
12 KiB

4 years ago
package main
import (
2 years ago
_ "Open_IM/cmd/open_im_api/docs"
apiAuth "Open_IM/internal/api/auth"
clientInit "Open_IM/internal/api/client_init"
"Open_IM/internal/api/conversation"
"Open_IM/internal/api/friend"
"Open_IM/internal/api/group"
"Open_IM/internal/api/manage"
2 years ago
apiChat "Open_IM/internal/api/msg"
3 years ago
"Open_IM/internal/api/office"
3 years ago
"Open_IM/internal/api/organization"
apiThird "Open_IM/internal/api/third"
"Open_IM/internal/api/user"
3 years ago
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
2 years ago
"Open_IM/pkg/common/middleware"
2 years ago
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/utils"
4 years ago
"flag"
3 years ago
"fmt"
2 years ago
//_ "github.com/razeencheng/demo-go/swaggo-gin/docs"
3 years ago
"io"
"os"
4 years ago
"strconv"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/gin-gonic/gin"
//"syscall"
3 years ago
"Open_IM/pkg/common/constant"
2 years ago
promePkg "Open_IM/pkg/common/prometheus"
4 years ago
)
2 years ago
// @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 /
4 years ago
func main() {
2 years ago
log.NewPrivateLog(constant.LogFileName)
gin.SetMode(gin.ReleaseMode)
3 years ago
f, _ := os.Create("../logs/api.log")
gin.DefaultWriter = io.MultiWriter(f)
2 years ago
// gin.SetMode(gin.DebugMode)
2 years ago
r := gin.New()
r.Use(gin.Recovery())
4 years ago
r.Use(utils.CorsHandler())
2 years ago
r.Use(middleware.GinParseOperationID)
2 years ago
log.Info("load config: ", config.Config)
2 years ago
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
2 years ago
if config.Config.Prometheus.Enable {
2 years ago
promePkg.NewApiRequestCounter()
promePkg.NewApiRequestFailedCounter()
promePkg.NewApiRequestSuccessCounter()
r.Use(promePkg.PromeTheusMiddleware)
2 years ago
r.GET("/metrics", promePkg.PrometheusHandler())
}
4 years ago
// user routing group, which handles user registration and login services
2 years ago
userRouterGroup := r.Group("/user")
{
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
userRouterGroup.POST("/set_global_msg_recv_opt", user.SetGlobalRecvMessageOpt)
userRouterGroup.POST("/get_users_info", user.GetUsersPublicInfo) //1
userRouterGroup.POST("/get_self_user_info", user.GetSelfUserInfo) //1
userRouterGroup.POST("/get_users_online_status", user.GetUsersOnlineStatus) //1
userRouterGroup.POST("/get_users_info_from_cache", user.GetUsersInfoFromCache)
userRouterGroup.POST("/get_user_friend_from_cache", user.GetFriendIDListFromCache)
userRouterGroup.POST("/get_black_list_from_cache", user.GetBlackIDListFromCache)
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
userRouterGroup.POST("/get_users", user.GetUsers)
}
2 years ago
////friend routing group
2 years ago
friendRouterGroup := r.Group("/friend")
{
// friendRouterGroup.POST("/get_friends_info", friend.GetFriendsInfo)
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
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
}
4 years ago
//group related routing group
3 years ago
groupRouterGroup := r.Group("/group")
2 years ago
groupRouterGroup.Use(func(c *gin.Context) {
2 years ago
userID, err := token_verify.ParseUserIDFromToken(c.GetHeader("token"), c.GetString("operationID"))
2 years ago
if err != nil {
c.String(400, err.Error())
2 years ago
c.Abort()
2 years ago
return
}
c.Set("opUserID", userID)
2 years ago
c.Next()
2 years ago
})
4 years ago
{
2 years ago
groupRouterGroup.POST("/create_group", group.NewCreateGroup) //1
groupRouterGroup.POST("/set_group_info", group.NewSetGroupInfo) //1
groupRouterGroup.POST("/join_group", group.JoinGroup) //1
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
groupRouterGroup.POST("/get_user_req_group_applicationList", group.GetUserReqGroupApplicationList)
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
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList)
groupRouterGroup.POST("/dismiss_group", group.DismissGroup) //
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)
groupRouterGroup.POST("/set_group_member_nickname", group.SetGroupMemberNickname)
groupRouterGroup.POST("/set_group_member_info", group.SetGroupMemberInfo)
groupRouterGroup.POST("/get_group_abstract_info", group.GetGroupAbstractInfo)
//groupRouterGroup.POST("/get_group_all_member_list_by_split", group.GetGroupAllMemberListBySplit)
3 years ago
}
2 years ago
superGroupRouterGroup := r.Group("/super_group")
{
superGroupRouterGroup.POST("/get_joined_group_list", group.GetJoinedSuperGroupList)
superGroupRouterGroup.POST("/get_groups_info", group.GetSuperGroupsInfo)
}
2 years ago
////certificate
2 years ago
authRouterGroup := r.Group("/auth")
{
authRouterGroup.POST("/user_register", apiAuth.UserRegister) //1
authRouterGroup.POST("/user_token", apiAuth.UserToken) //1
authRouterGroup.POST("/parse_token", apiAuth.ParseToken) //1
authRouterGroup.POST("/force_logout", apiAuth.ForceLogout) //1
}
2 years ago
////Third service
2 years ago
thirdGroup := r.Group("/third")
{
thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential)
thirdGroup.POST("/ali_oss_credential", apiThird.AliOSSCredential)
thirdGroup.POST("/minio_storage_credential", apiThird.MinioStorageCredential)
thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile)
thirdGroup.POST("/upload_update_app", apiThird.UploadUpdateApp)
thirdGroup.POST("/get_download_url", apiThird.GetDownloadURL)
thirdGroup.POST("/get_rtc_invitation_info", apiThird.GetRTCInvitationInfo)
thirdGroup.POST("/get_rtc_invitation_start_app", apiThird.GetRTCInvitationInfoStartApp)
thirdGroup.POST("/fcm_update_token", apiThird.FcmUpdateToken)
thirdGroup.POST("/aws_storage_credential", apiThird.AwsStorageCredential)
thirdGroup.POST("/set_app_badge", apiThird.SetAppBadge)
}
2 years ago
////Message
2 years ago
chatGroup := r.Group("/msg")
{
chatGroup.POST("/newest_seq", apiChat.GetSeq)
chatGroup.POST("/send_msg", apiChat.SendMsg)
chatGroup.POST("/pull_msg_by_seq", apiChat.PullMsgBySeqList)
chatGroup.POST("/del_msg", apiChat.DelMsg)
chatGroup.POST("/del_super_group_msg", apiChat.DelSuperGroupMsg)
chatGroup.POST("/clear_msg", apiChat.ClearMsg)
chatGroup.POST("/manage_send_msg", manage.ManagementSendMsg)
chatGroup.POST("/batch_send_msg", manage.ManagementBatchSendMsg)
chatGroup.POST("/check_msg_is_send_success", manage.CheckMsgIsSendSuccess)
chatGroup.POST("/set_msg_min_seq", apiChat.SetMsgMinSeq)
chatGroup.POST("/set_message_reaction_extensions", apiChat.SetMessageReactionExtensions)
chatGroup.POST("/get_message_list_reaction_extensions", apiChat.GetMessageListReactionExtensions)
chatGroup.POST("/add_message_reaction_extensions", apiChat.AddMessageReactionExtensions)
chatGroup.POST("/delete_message_reaction_extensions", apiChat.DeleteMessageReactionExtensions)
}
2 years ago
////Conversation
2 years ago
conversationGroup := r.Group("/conversation")
{ //1
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)
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
conversationGroup.POST("/modify_conversation_field", conversation.ModifyConversationField)
}
2 years ago
//// office
2 years ago
officeGroup := r.Group("/office")
{
officeGroup.POST("/get_user_tags", office.GetUserTags)
officeGroup.POST("/get_user_tag_by_id", office.GetUserTagByID)
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)
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
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)
officeGroup.POST("/get_work_moment_by_id", office.GetWorkMomentByID)
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)
officeGroup.POST("/delete_comment", office.DeleteComment)
}
2 years ago
//
2 years ago
organizationGroup := r.Group("/organization")
{
organizationGroup.POST("/create_department", organization.CreateDepartment)
organizationGroup.POST("/update_department", organization.UpdateDepartment)
organizationGroup.POST("/get_sub_department", organization.GetSubDepartment)
organizationGroup.POST("/delete_department", organization.DeleteDepartment)
organizationGroup.POST("/get_all_department", organization.GetAllDepartment)
organizationGroup.POST("/create_organization_user", organization.CreateOrganizationUser)
organizationGroup.POST("/update_organization_user", organization.UpdateOrganizationUser)
organizationGroup.POST("/delete_organization_user", organization.DeleteOrganizationUser)
organizationGroup.POST("/create_department_member", organization.CreateDepartmentMember)
organizationGroup.POST("/get_user_in_department", organization.GetUserInDepartment)
organizationGroup.POST("/update_user_in_department", organization.UpdateUserInDepartment)
organizationGroup.POST("/get_department_member", organization.GetDepartmentMember)
organizationGroup.POST("/delete_user_in_department", organization.DeleteUserInDepartment)
organizationGroup.POST("/get_user_in_organization", organization.GetUserInOrganization)
}
2 years ago
//
2 years ago
initGroup := r.Group("/init")
{
initGroup.POST("/set_client_config", clientInit.SetClientInitConfig)
initGroup.POST("/get_client_config", clientInit.GetClientInitConfig)
}
2 years ago
go utils.RegisterConf()
3 years ago
go apiThird.MinioInit()
defaultPorts := config.Config.Api.GinPort
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10002 as port")
4 years ago
flag.Parse()
address := "0.0.0.0:" + strconv.Itoa(*ginPort)
if config.Config.Api.ListenIP != "" {
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
}
2 years ago
fmt.Println("start api server, address: ", address, ", OpenIM version: ", constant.CurrentVersion)
err := r.Run(address)
3 years ago
if err != nil {
2 years ago
log.Error("", "api run failed ", address, err.Error())
panic("api start failed " + err.Error())
3 years ago
}
4 years ago
}