47 lines
950 B
Go
47 lines
950 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"log"
|
|
"strconv"
|
|
"user/controller"
|
|
"user/config"
|
|
"user/db"
|
|
"user/logs"
|
|
)
|
|
|
|
func InitMysql() {
|
|
c := config.GetMysqlConfig()
|
|
if c == nil{
|
|
logs.Error("cannnot connect mysql server")
|
|
}else {
|
|
db.Init()
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
e := config.Init("user.yaml")
|
|
if nil != e{
|
|
log.Println(e.Error())
|
|
}
|
|
db.Init()
|
|
r := gin.Default()
|
|
{
|
|
/** 添加或修改用户 **/
|
|
r.POST("/api/user", controller.SetUser)
|
|
/** 删除用户 **/
|
|
r.DELETE("/api/user", controller.DelUser)
|
|
/** 获取单独用户详情信息 methods(id) **/
|
|
r.GET("/api/user", controller.GetUser)
|
|
/** 获取所有用户 **/
|
|
r.GET("/api/users", controller.GetUsers)
|
|
/** 用户登录 **/
|
|
r.POST("/api/login", controller.Login)
|
|
/** 用户注册 **/
|
|
r.POST("/api/register", controller.Register)
|
|
/** 用户退出登陆 **/
|
|
r.GET("/api/logout", controller.Logout)
|
|
}
|
|
r.Run(":" + strconv.Itoa(config.GetPort()))
|
|
}
|