50 lines
942 B
Go
50 lines
942 B
Go
package providers
|
|
|
|
import (
|
|
"framework_v2/internal/access"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func InitGin() {
|
|
access.Router = gin.Default()
|
|
access.Router.Use(gin.Recovery())
|
|
}
|
|
|
|
type httpMethod int
|
|
|
|
var httpMethodStr = []string{"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"}
|
|
|
|
func (h httpMethod) String() string {
|
|
return httpMethodStr[h-1]
|
|
}
|
|
|
|
const (
|
|
GET httpMethod = iota + 1
|
|
POST
|
|
PUT
|
|
DELETE
|
|
PATCH
|
|
HEAD
|
|
OPTIONS
|
|
)
|
|
|
|
type HandlerFunc func(c *gin.Context, metadata *access.Metadata)
|
|
|
|
func HandleRoute(method httpMethod, relativePath string, handlers ...HandlerFunc) {
|
|
access.Router.Handle(method.String(), relativePath, func(c *gin.Context) {
|
|
handleWithMetadata(c, handlers...)
|
|
})
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|