初始化
This commit is contained in:
parent
f581b8d64a
commit
8cee5f1f2f
|
@ -0,0 +1,7 @@
|
|||
package controllers
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package front
|
||||
|
||||
type LoginRequest struct {
|
||||
UserName string `json:"user_name"`
|
||||
}
|
|
@ -8,7 +8,9 @@ import (
|
|||
"qteam/app/constants/common"
|
||||
"qteam/app/constants/errorcode"
|
||||
"qteam/app/http/controllers"
|
||||
"qteam/app/http/requestmapping"
|
||||
"qteam/app/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Auth() gin.HandlerFunc {
|
||||
|
@ -38,3 +40,22 @@ func AdminAuth() gin.HandlerFunc {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateRequest() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var path = c.Request.RequestURI
|
||||
var handler func() interface{}
|
||||
if strings.Index(path, "api") >= 0 {
|
||||
handler = requestmapping.BackendRequestMap[path]
|
||||
} else {
|
||||
handler = requestmapping.FrontRequestMap[path]
|
||||
}
|
||||
if handler == nil {
|
||||
utils.Log(c, "path", path)
|
||||
controllers.HandCodeRes(c, nil, errorcode.NotFound)
|
||||
} else {
|
||||
c.Set("request", handler())
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package requestmapping
|
||||
|
||||
import "qteam/app/http/entities/front"
|
||||
|
||||
var BackendRequestMap = map[string]func() interface{}{
|
||||
"/v1/login": func() interface{} {
|
||||
return new(front.LoginRequest)
|
||||
},
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package requestmapping
|
||||
|
||||
import "qteam/app/http/entities/front"
|
||||
|
||||
var FrontRequestMap = map[string]func() interface{}{
|
||||
"/v1/login": func() interface{} {
|
||||
return new(front.LoginRequest)
|
||||
},
|
||||
}
|
|
@ -43,9 +43,9 @@ func RegisterRoute(router *gin.Engine) {
|
|||
router.NoRoute(controllers.Error404)
|
||||
|
||||
//api版本
|
||||
//v1 := router.Group("/v1")
|
||||
v1 := router.Group("/v1", middlewares.ValidateRequest())
|
||||
{
|
||||
//v1.GET("/banner_list", controllers.GetBannerList)
|
||||
v1.GET("/login", controllers.Login)
|
||||
}
|
||||
|
||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
|
Loading…
Reference in New Issue