v0.0.483
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m37s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m37s
This commit is contained in:
parent
6ded615723
commit
bc5c61e43d
@ -15,16 +15,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PreContext struct {
|
type PreContext struct {
|
||||||
ginCtx *gin.Context
|
ginCtx *gin.Context
|
||||||
wrapper *GinWrapper
|
wrapper *GinWrapper
|
||||||
uri any
|
uri any
|
||||||
query any
|
query any
|
||||||
body any
|
body any
|
||||||
rawbody *[]byte
|
rawbody *[]byte
|
||||||
form any
|
form any
|
||||||
header any
|
header any
|
||||||
timeout *time.Duration
|
timeout *time.Duration
|
||||||
persistantData *preContextData // must be a ptr, so that we can get the values back in out Wrap func
|
persistantData *preContextData // must be a ptr, so that we can get the values back in out Wrap func
|
||||||
|
ignoreWrongContentType bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type preContextData struct {
|
type preContextData struct {
|
||||||
@ -71,7 +72,12 @@ func (pctx *PreContext) WithSession(sessionObj SessionObject) *PreContext {
|
|||||||
return pctx
|
return pctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
func (pctx *PreContext) IgnoreWrongContentType() *PreContext {
|
||||||
|
pctx.ignoreWrongContentType = true
|
||||||
|
return pctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pctx PreContext) Start() (*AppContext, *gin.Context, *InspectableHTTPErrorResponse) {
|
||||||
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").
|
||||||
@ -102,10 +108,12 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
|||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(Error(err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := exerr.New(exerr.TypeBindFailJSON, "missing JSON body").
|
if !pctx.ignoreWrongContentType {
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
err := exerr.New(exerr.TypeBindFailJSON, "missing JSON body").
|
||||||
Build()
|
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +152,12 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
|||||||
return nil, nil, langext.Ptr(Error(err))
|
return nil, nil, langext.Ptr(Error(err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := exerr.New(exerr.TypeBindFailFormData, "missing form body").
|
if !pctx.ignoreWrongContentType {
|
||||||
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
err := exerr.New(exerr.TypeBindFailFormData, "missing form body").
|
||||||
Build()
|
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
||||||
return nil, nil, langext.Ptr(Error(err))
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,13 @@ type InspectableHTTPResponse interface {
|
|||||||
Headers() []string
|
Headers() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InspectableHTTPErrorResponse interface {
|
||||||
|
HTTPResponse
|
||||||
|
InspectableHTTPResponse
|
||||||
|
|
||||||
|
Error() error
|
||||||
|
}
|
||||||
|
|
||||||
func NotImplemented() HTTPResponse {
|
func NotImplemented() HTTPResponse {
|
||||||
return Error(exerr.New(exerr.TypeNotImplemented, "").Build())
|
return Error(exerr.New(exerr.TypeNotImplemented, "").Build())
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,10 @@ type jsonAPIErrResponse struct {
|
|||||||
cookies []cookieval
|
cookies []cookieval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j jsonAPIErrResponse) Error() error {
|
||||||
|
return j.err
|
||||||
|
}
|
||||||
|
|
||||||
func (j jsonAPIErrResponse) Write(g *gin.Context) {
|
func (j jsonAPIErrResponse) Write(g *gin.Context) {
|
||||||
for _, v := range j.headers {
|
for _, v := range j.headers {
|
||||||
g.Header(v.Key, v.Val)
|
g.Header(v.Key, v.Val)
|
||||||
@ -64,7 +68,7 @@ func (j jsonAPIErrResponse) Unwrap() error {
|
|||||||
return j.err
|
return j.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Error(e error) HTTPResponse {
|
func Error(e error) InspectableHTTPErrorResponse {
|
||||||
return &jsonAPIErrResponse{
|
return &jsonAPIErrResponse{
|
||||||
err: exerr.FromError(e),
|
err: exerr.FromError(e),
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.482"
|
const GoextVersion = "0.0.483"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-07-12T16:33:42+0200"
|
const GoextVersionTimestamp = "2024-07-16T15:08:37+0200"
|
||||||
|
Loading…
Reference in New Issue
Block a user