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