v0.0.484
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m58s
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m58s
This commit is contained in:
parent
bc5c61e43d
commit
ff8e066135
@ -27,6 +27,8 @@ type GinWrapper struct {
|
|||||||
listenerBeforeRequest []func(g *gin.Context)
|
listenerBeforeRequest []func(g *gin.Context)
|
||||||
listenerAfterRequest []func(g *gin.Context, resp HTTPResponse)
|
listenerAfterRequest []func(g *gin.Context, resp HTTPResponse)
|
||||||
|
|
||||||
|
buildRequestBindError func(g *gin.Context, fieldtype string, err error) HTTPResponse
|
||||||
|
|
||||||
routeSpecs []ginRouteSpec
|
routeSpecs []ginRouteSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,15 +40,16 @@ type ginRouteSpec struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
AllowCors *bool // Add cors handler to allow all CORS requests on the default http methods
|
AllowCors *bool // Add cors handler to allow all CORS requests on the default http methods
|
||||||
GinDebug *bool // Set gin.debug to true (adds more logs)
|
GinDebug *bool // Set gin.debug to true (adds more logs)
|
||||||
SuppressGinLogs *bool // Suppress our custom gin logs (even if GinDebug == true)
|
SuppressGinLogs *bool // Suppress our custom gin logs (even if GinDebug == true)
|
||||||
BufferBody *bool // Buffers the input body stream, this way the ginext error handler can later include the whole request body
|
BufferBody *bool // Buffers the input body stream, this way the ginext error handler can later include the whole request body
|
||||||
Timeout *time.Duration // The default handler timeout
|
Timeout *time.Duration // The default handler timeout
|
||||||
ListenerBeforeRequest []func(g *gin.Context) // Register listener that are called before the handler method
|
ListenerBeforeRequest []func(g *gin.Context) // Register listener that are called before the handler method
|
||||||
ListenerAfterRequest []func(g *gin.Context, resp HTTPResponse) // Register listener that are called after the handler method
|
ListenerAfterRequest []func(g *gin.Context, resp HTTPResponse) // Register listener that are called after the handler method
|
||||||
DebugTrimHandlerPrefixes []string // Trim these prefixes from the handler names in the debug print
|
DebugTrimHandlerPrefixes []string // Trim these prefixes from the handler names in the debug print
|
||||||
DebugReplaceHandlerNames map[string]string // Replace handler names in debug output
|
DebugReplaceHandlerNames map[string]string // Replace handler names in debug output
|
||||||
|
BuildRequestBindError func(g *gin.Context, fieldtype string, err error) HTTPResponse // Override function which generates the HTTPResponse errors that are returned by the preContext..Start() methids
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEngine creates a new (wrapped) ginEngine
|
// NewEngine creates a new (wrapped) ginEngine
|
||||||
@ -77,6 +80,7 @@ func NewEngine(opt Options) *GinWrapper {
|
|||||||
requestTimeout: langext.Coalesce(opt.Timeout, 24*time.Hour),
|
requestTimeout: langext.Coalesce(opt.Timeout, 24*time.Hour),
|
||||||
listenerBeforeRequest: opt.ListenerBeforeRequest,
|
listenerBeforeRequest: opt.ListenerBeforeRequest,
|
||||||
listenerAfterRequest: opt.ListenerAfterRequest,
|
listenerAfterRequest: opt.ListenerAfterRequest,
|
||||||
|
buildRequestBindError: langext.Conditional(opt.BuildRequestBindError == nil, defaultBuildRequestBindError, opt.BuildRequestBindError),
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.RedirectFixedPath = false
|
engine.RedirectFixedPath = false
|
||||||
@ -222,3 +226,7 @@ func (w *GinWrapper) ForwardRequest(writer http.ResponseWriter, req *http.Reques
|
|||||||
func (w *GinWrapper) ListRoutes() []gin.RouteInfo {
|
func (w *GinWrapper) ListRoutes() []gin.RouteInfo {
|
||||||
return w.engine.Routes()
|
return w.engine.Routes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defaultBuildRequestBindError(g *gin.Context, fieldtype string, err error) HTTPResponse {
|
||||||
|
return Error(err)
|
||||||
|
}
|
||||||
|
@ -77,14 +77,14 @@ func (pctx *PreContext) IgnoreWrongContentType() *PreContext {
|
|||||||
return pctx
|
return pctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPErrorResponse) {
|
func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
||||||
if pctx.uri != nil {
|
if pctx.uri != nil {
|
||||||
if err := pctx.ginCtx.ShouldBindUri(pctx.uri); err != nil {
|
if err := pctx.ginCtx.ShouldBindUri(pctx.uri); err != nil {
|
||||||
err = exerr.Wrap(err, "Failed to read uri").
|
err = exerr.Wrap(err, "Failed to read uri").
|
||||||
WithType(exerr.TypeBindFailURI).
|
WithType(exerr.TypeBindFailURI).
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.uri)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.uri)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "URI", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
WithType(exerr.TypeBindFailQuery).
|
WithType(exerr.TypeBindFailQuery).
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.query)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.query)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "QUERY", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,14 +105,14 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
WithType(exerr.TypeBindFailJSON).
|
WithType(exerr.TypeBindFailJSON).
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "BODY", err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !pctx.ignoreWrongContentType {
|
if !pctx.ignoreWrongContentType {
|
||||||
err := exerr.New(exerr.TypeBindFailJSON, "missing JSON body").
|
err := exerr.New(exerr.TypeBindFailJSON, "missing JSON body").
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "BODY", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,14 +121,14 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
if brc, ok := pctx.ginCtx.Request.Body.(dataext.BufferedReadCloser); ok {
|
if brc, ok := pctx.ginCtx.Request.Body.(dataext.BufferedReadCloser); ok {
|
||||||
v, err := brc.BufferedAll()
|
v, err := brc.BufferedAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "URI", err))
|
||||||
}
|
}
|
||||||
*pctx.rawbody = v
|
*pctx.rawbody = v
|
||||||
} else {
|
} else {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
_, err := io.Copy(buf, pctx.ginCtx.Request.Body)
|
_, err := io.Copy(buf, pctx.ginCtx.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "URI", err))
|
||||||
}
|
}
|
||||||
*pctx.rawbody = buf.Bytes()
|
*pctx.rawbody = buf.Bytes()
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
WithType(exerr.TypeBindFailFormData).
|
WithType(exerr.TypeBindFailFormData).
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "FORM", err))
|
||||||
}
|
}
|
||||||
} else if pctx.ginCtx.ContentType() == "application/x-www-form-urlencoded" {
|
} else if pctx.ginCtx.ContentType() == "application/x-www-form-urlencoded" {
|
||||||
if err := pctx.ginCtx.ShouldBindWith(pctx.form, binding.Form); err != nil {
|
if err := pctx.ginCtx.ShouldBindWith(pctx.form, binding.Form); err != nil {
|
||||||
@ -149,14 +149,14 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
WithType(exerr.TypeBindFailFormData).
|
WithType(exerr.TypeBindFailFormData).
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "FORM", err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !pctx.ignoreWrongContentType {
|
if !pctx.ignoreWrongContentType {
|
||||||
err := exerr.New(exerr.TypeBindFailFormData, "missing form body").
|
err := exerr.New(exerr.TypeBindFailFormData, "missing form body").
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "FORM", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
WithType(exerr.TypeBindFailHeader).
|
WithType(exerr.TypeBindFailHeader).
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.query)).
|
Str("struct_type", fmt.Sprintf("%T", pctx.query)).
|
||||||
Build()
|
Build()
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "HEADER", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPError
|
|||||||
err := pctx.persistantData.sessionObj.Init(pctx.ginCtx, actx)
|
err := pctx.persistantData.sessionObj.Init(pctx.ginCtx, actx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
actx.Cancel()
|
actx.Cancel()
|
||||||
return nil, nil, langext.Ptr(Error(exerr.Wrap(err, "Failed to init session").Build()))
|
return nil, nil, langext.Ptr(pctx.wrapper.buildRequestBindError(pctx.ginCtx, "INIT", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,8 @@ type InspectableHTTPResponse interface {
|
|||||||
Headers() []string
|
Headers() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type InspectableHTTPErrorResponse interface {
|
type HTTPErrorResponse interface {
|
||||||
HTTPResponse
|
HTTPResponse
|
||||||
InspectableHTTPResponse
|
|
||||||
|
|
||||||
Error() error
|
Error() error
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.483"
|
const GoextVersion = "0.0.484"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-07-16T15:08:37+0200"
|
const GoextVersionTimestamp = "2024-07-16T15:16:56+0200"
|
||||||
|
Loading…
Reference in New Issue
Block a user