v0.0.588
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m37s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m37s
This commit is contained in:
@@ -2,8 +2,9 @@ package ginext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WHandlerFunc func(PreContext) HTTPResponse
|
||||
@@ -58,3 +59,31 @@ func Wrap(w *GinWrapper, fn WHandlerFunc) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WrapHTTPHandler(w *GinWrapper, fn http.Handler) gin.HandlerFunc {
|
||||
return func(g *gin.Context) {
|
||||
for _, lstr := range w.listenerBeforeRequest {
|
||||
lstr(g)
|
||||
}
|
||||
|
||||
fn.ServeHTTP(g.Writer, g.Request)
|
||||
|
||||
for _, lstr := range w.listenerAfterRequest {
|
||||
lstr(g, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WrapHTTPHandlerFunc(w *GinWrapper, fn http.HandlerFunc) gin.HandlerFunc {
|
||||
return func(g *gin.Context) {
|
||||
for _, lstr := range w.listenerBeforeRequest {
|
||||
lstr(g)
|
||||
}
|
||||
|
||||
fn(g.Writer, g.Request)
|
||||
|
||||
for _, lstr := range w.listenerAfterRequest {
|
||||
lstr(g, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package ginext
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"path"
|
||||
"reflect"
|
||||
@@ -148,6 +148,68 @@ func (w *GinRouteBuilder) Handle(handler WHandlerFunc) {
|
||||
})
|
||||
}
|
||||
|
||||
func (w *GinRouteBuilder) HandleRawHTTPHandler(f http.Handler) {
|
||||
if w.routes.wrapper.bufferBody {
|
||||
arr := make([]gin.HandlerFunc, 0, len(w.handlers)+1)
|
||||
arr = append(arr, BodyBuffer)
|
||||
arr = append(arr, w.handlers...)
|
||||
w.handlers = arr
|
||||
}
|
||||
|
||||
middlewareNames := langext.ArrMap(w.handlers, func(v gin.HandlerFunc) string { return nameOfFunction(v) })
|
||||
|
||||
w.handlers = append(w.handlers, WrapHTTPHandler(w.routes.wrapper, f))
|
||||
|
||||
methodName := w.method
|
||||
|
||||
if w.method == "*" {
|
||||
methodName = "ANY"
|
||||
for _, method := range anyMethods {
|
||||
w.routes.routes.Handle(method, w.relPath, w.handlers...)
|
||||
}
|
||||
} else {
|
||||
w.routes.routes.Handle(w.method, w.relPath, w.handlers...)
|
||||
}
|
||||
|
||||
w.routes.wrapper.routeSpecs = append(w.routes.wrapper.routeSpecs, ginRouteSpec{
|
||||
Method: methodName,
|
||||
URL: w.absPath,
|
||||
Middlewares: middlewareNames,
|
||||
Handler: "[HTTPHandler]",
|
||||
})
|
||||
}
|
||||
|
||||
func (w *GinRouteBuilder) HandleRawHTTPHandlerFunc(f http.HandlerFunc) {
|
||||
if w.routes.wrapper.bufferBody {
|
||||
arr := make([]gin.HandlerFunc, 0, len(w.handlers)+1)
|
||||
arr = append(arr, BodyBuffer)
|
||||
arr = append(arr, w.handlers...)
|
||||
w.handlers = arr
|
||||
}
|
||||
|
||||
middlewareNames := langext.ArrMap(w.handlers, func(v gin.HandlerFunc) string { return nameOfFunction(v) })
|
||||
|
||||
w.handlers = append(w.handlers, WrapHTTPHandlerFunc(w.routes.wrapper, f))
|
||||
|
||||
methodName := w.method
|
||||
|
||||
if w.method == "*" {
|
||||
methodName = "ANY"
|
||||
for _, method := range anyMethods {
|
||||
w.routes.routes.Handle(method, w.relPath, w.handlers...)
|
||||
}
|
||||
} else {
|
||||
w.routes.routes.Handle(w.method, w.relPath, w.handlers...)
|
||||
}
|
||||
|
||||
w.routes.wrapper.routeSpecs = append(w.routes.wrapper.routeSpecs, ginRouteSpec{
|
||||
Method: methodName,
|
||||
URL: w.absPath,
|
||||
Middlewares: middlewareNames,
|
||||
Handler: "[HTTPHandlerFunc]",
|
||||
})
|
||||
}
|
||||
|
||||
func (w *GinWrapper) NoRoute(handler WHandlerFunc) {
|
||||
|
||||
handlers := make([]gin.HandlerFunc, 0)
|
||||
|
Reference in New Issue
Block a user