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

81 lines
2.7 KiB

package main
import (
"Open_IM/internal/demo/register"
"Open_IM/pkg/utils"
"flag"
3 years ago
"fmt"
3 years ago
"io"
"os"
"strconv"
"Open_IM/pkg/common/config"
3 years ago
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
2 years ago
2 years ago
promePkg "Open_IM/pkg/common/prometheus"
"github.com/gin-gonic/gin"
)
func main() {
3 years ago
log.NewPrivateLog(constant.LogFileName)
3 years ago
gin.SetMode(gin.ReleaseMode)
f, _ := os.Create("../logs/api.log")
gin.DefaultWriter = io.MultiWriter(f)
r := gin.Default()
r.Use(utils.CorsHandler())
2 years ago
if config.Config.Prometheus.Enable {
r.GET("/metrics", promePkg.PrometheusHandler())
}
3 years ago
authRouterGroup := r.Group("/demo")
{
authRouterGroup.POST("/code", register.SendVerificationCode)
authRouterGroup.POST("/verify", register.Verify)
authRouterGroup.POST("/password", register.SetPassword)
authRouterGroup.POST("/login", register.Login)
3 years ago
authRouterGroup.POST("/reset_password", register.ResetPassword)
2 years ago
authRouterGroup.POST("/check_login", register.CheckLoginLimit)
}
2 years ago
demoRouterGroup := r.Group("/auth")
{
demoRouterGroup.POST("/code", register.SendVerificationCode)
demoRouterGroup.POST("/verify", register.Verify)
demoRouterGroup.POST("/password", register.SetPassword)
demoRouterGroup.POST("/login", register.Login)
demoRouterGroup.POST("/reset_password", register.ResetPassword)
2 years ago
demoRouterGroup.POST("/check_login", register.CheckLoginLimit)
2 years ago
}
2 years ago
//deprecated
cmsRouterGroup := r.Group("/cms_admin")
2 years ago
{
cmsRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode)
cmsRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode)
cmsRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes)
2 years ago
2 years ago
cmsRouterGroup.POST("/query_user_ip_limit_login", register.QueryUserIDLimitLogin)
cmsRouterGroup.POST("/add_user_ip_limit_login", register.AddUserIPLimitLogin)
cmsRouterGroup.POST("/remove_user_ip_limit_login", register.RemoveUserIPLimitLogin)
cmsRouterGroup.POST("/query_ip_register", register.QueryIPRegister)
cmsRouterGroup.POST("/add_ip_limit", register.AddIPLimit)
cmsRouterGroup.POST("/remove_ip_Limit", register.RemoveIPLimit)
2 years ago
}
defaultPorts := config.Config.Demo.Port
2 years ago
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10004 as port")
flag.Parse()
address := "0.0.0.0:" + strconv.Itoa(*ginPort)
if config.Config.Api.ListenIP != "" {
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
}
address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort)
2 years ago
fmt.Println("start demo api server address: ", address, "OpenIM version: ", constant.CurrentVersion, "\n")
2 years ago
go register.OnboardingProcessRoutine()
2 years ago
go register.ImportFriendRoutine()
err := r.Run(address)
3 years ago
if err != nil {
log.Error("", "run failed ", *ginPort, err.Error())
}
}