|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"Open_IM/internal/demo/register"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/config"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.NewPrivateLog(constant.LogFileName)
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
f, _ := os.Create("../logs/api.log")
|
|
|
|
gin.DefaultWriter = io.MultiWriter(f)
|
|
|
|
|
|
|
|
r := gin.Default()
|
|
|
|
r.Use(utils.CorsHandler())
|
|
|
|
|
|
|
|
authRouterGroup := r.Group("/demo")
|
|
|
|
{
|
|
|
|
authRouterGroup.POST("/code", register.SendVerificationCode)
|
|
|
|
authRouterGroup.POST("/verify", register.Verify)
|
|
|
|
authRouterGroup.POST("/password", register.SetPassword)
|
|
|
|
authRouterGroup.POST("/login", register.Login)
|
|
|
|
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
|
|
|
}
|
|
|
|
|
|
|
|
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
|
|
|
flag.Parse()
|
|
|
|
fmt.Println("start demo api server, port: ", *ginPort)
|
|
|
|
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)
|
|
|
|
fmt.Println("start demo api server address: ", address)
|
|
|
|
err := r.Run(address)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("", "run failed ", *ginPort, err.Error())
|
|
|
|
}
|
|
|
|
}
|