改进 路由和 http ctx
This commit is contained in:
parent
12c25e0b22
commit
bc4e145689
@ -2,10 +2,12 @@ package access
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"framework_v2/internal/providers"
|
"framework_v2/internal/providers"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User providers.JwtIDToken
|
type User providers.JwtIDToken
|
||||||
|
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
|
Http *gin.Context
|
||||||
User User
|
User User
|
||||||
}
|
}
|
||||||
|
@ -28,22 +28,22 @@ const (
|
|||||||
OPTIONS
|
OPTIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
type HandlerFunc func(c *gin.Context, metadata *access.Metadata)
|
type HandlerFunc func(metadata *access.Metadata)
|
||||||
|
|
||||||
func HandleRoute(method httpMethod, relativePath string, handlers ...HandlerFunc) {
|
func HandleRoute(method httpMethod, relativePath string, controller HandlerFunc, middlewares ...gin.HandlerFunc) {
|
||||||
access.Router.Handle(method.String(), relativePath, func(c *gin.Context) {
|
access.Router.Handle(method.String(), relativePath, func(c *gin.Context) {
|
||||||
handleWithMetadata(c, handlers...)
|
for _, middleware := range middlewares {
|
||||||
|
middleware(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleWithMetadata(c, controller)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUser(c *gin.Context) *access.User {
|
func handleWithMetadata(c *gin.Context, controller HandlerFunc) {
|
||||||
return &access.User{}
|
var metadata = &access.Metadata{
|
||||||
}
|
Http: c,
|
||||||
|
|
||||||
func handleWithMetadata(c *gin.Context, handlers ...HandlerFunc) {
|
|
||||||
var metadata = &access.Metadata{}
|
|
||||||
|
|
||||||
for _, handler := range handlers {
|
|
||||||
handler(c, metadata)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controller(metadata)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user