blog_backend_api/main.go

58 lines
1.3 KiB
Go
Raw Normal View History

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()
2019-01-31 08:57:22 +00:00
e = config.InitRedis()
if nil != e{
logs.Error(e.Error())
return
}
2019-01-25 09:11:15 +00:00
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)
2019-01-31 08:57:22 +00:00
r.POST("/api/email_code",controller.SendEmailCode)
2019-01-25 09:11:15 +00:00
}
r.Run(":" + strconv.Itoa(config.GetPort()))
}