2019-01-25 09:11:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2019-01-29 13:57:53 +00:00
|
|
|
"github.com/tommy351/gin-sessions"
|
2019-01-25 09:11:15 +00:00
|
|
|
"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())
|
|
|
|
}
|
2019-01-29 13:57:53 +00:00
|
|
|
logs.Init(config.GetLogConfig().Dir,config.GetLogConfig().File,config.GetLogConfig().Level,config.GetLogConfig().SaveFile)
|
2019-01-25 09:11:15 +00:00
|
|
|
db.Init()
|
|
|
|
r := gin.Default()
|
2019-01-29 13:57:53 +00:00
|
|
|
store := sessions.NewCookieStore([]byte("secret123"))
|
|
|
|
r.Use(sessions.Middleware("my_session", store))
|
|
|
|
|
2019-01-25 09:11:15 +00:00
|
|
|
{
|
|
|
|
/** 添加或修改用户 **/
|
|
|
|
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()))
|
|
|
|
}
|