diff --git a/app/http/controllers/user.go b/app/http/controllers/user.go new file mode 100644 index 0000000..83f02a4 --- /dev/null +++ b/app/http/controllers/user.go @@ -0,0 +1,7 @@ +package controllers + +import "github.com/gin-gonic/gin" + +func Login(c *gin.Context) { + +} diff --git a/app/http/entities/front/user.go b/app/http/entities/front/user.go new file mode 100644 index 0000000..544f4f3 --- /dev/null +++ b/app/http/entities/front/user.go @@ -0,0 +1,5 @@ +package front + +type LoginRequest struct { + UserName string `json:"user_name"` +} diff --git a/app/http/middlewares/base.go b/app/http/middlewares/base.go index 0e4f742..b6dd4b8 100644 --- a/app/http/middlewares/base.go +++ b/app/http/middlewares/base.go @@ -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() + } + } +} diff --git a/app/http/requestmapping/backend.go b/app/http/requestmapping/backend.go new file mode 100644 index 0000000..c5845bf --- /dev/null +++ b/app/http/requestmapping/backend.go @@ -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) + }, +} diff --git a/app/http/requestmapping/front.go b/app/http/requestmapping/front.go new file mode 100644 index 0000000..8e69787 --- /dev/null +++ b/app/http/requestmapping/front.go @@ -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) + }, +} diff --git a/app/http/routes/route.go b/app/http/routes/route.go index 92e11a3..96c677c 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -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))