background/main.go

52 lines
1.2 KiB
Go

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