v0.0.196
This commit is contained in:
parent
a73d7d1654
commit
7fe3e66cad
@ -2,8 +2,10 @@ package ginext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
||||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
)
|
)
|
||||||
@ -40,33 +42,55 @@ func (pctx *PreContext) Form(form any) *PreContext {
|
|||||||
func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
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 {
|
||||||
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, commonApiErr.BindFailURI, "Failed to read uri", err))
|
err = exerr.Wrap(err, "Failed to read uri").
|
||||||
|
WithType(exerr.TypeBindFailURI).
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.uri)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pctx.query != nil {
|
if pctx.query != nil {
|
||||||
if err := pctx.ginCtx.ShouldBindQuery(pctx.query); err != nil {
|
if err := pctx.ginCtx.ShouldBindQuery(pctx.query); err != nil {
|
||||||
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, commonApiErr.BindFailQuery, "Failed to read query", err))
|
err = exerr.Wrap(err, "Failed to read query").
|
||||||
|
WithType(exerr.TypeBindFailQuery).
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.query)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pctx.body != nil {
|
if pctx.body != nil {
|
||||||
if pctx.ginCtx.ContentType() == "application/json" {
|
if pctx.ginCtx.ContentType() == "application/json" {
|
||||||
if err := pctx.ginCtx.ShouldBindJSON(pctx.body); err != nil {
|
if err := pctx.ginCtx.ShouldBindJSON(pctx.body); err != nil {
|
||||||
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, commonApiErr.BindFailJSON, "Failed to read body", err))
|
err = exerr.Wrap(err, "Failed to read json-body").
|
||||||
|
WithType(exerr.TypeBindFailJSON).
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, commonApiErr.BindFailJSON, "missing JSON body", nil))
|
err := exerr.New(exerr.TypeBindFailJSON, "missing JSON body").
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.body)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pctx.form != nil {
|
if pctx.form != nil {
|
||||||
if pctx.ginCtx.ContentType() == "multipart/form-data" {
|
if pctx.ginCtx.ContentType() == "multipart/form-data" {
|
||||||
if err := pctx.ginCtx.ShouldBindWith(pctx.form, binding.Form); err != nil {
|
if err := pctx.ginCtx.ShouldBindWith(pctx.form, binding.Form); err != nil {
|
||||||
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, commonApiErr.BindFailFormData, "Failed to read multipart-form", err))
|
err = exerr.Wrap(err, "Failed to read multipart-form").
|
||||||
|
WithType(exerr.TypeBindFailFormData).
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, commonApiErr.BindFailJSON, "missing form body", nil))
|
err := exerr.New(exerr.TypeBindFailFormData, "missing form body").
|
||||||
|
Str("struct_type", fmt.Sprintf("%T", pctx.form)).
|
||||||
|
Build()
|
||||||
|
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.195"
|
const GoextVersion = "0.0.196"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2023-07-24T11:42:52+0200"
|
const GoextVersionTimestamp = "2023-07-24T11:47:47+0200"
|
||||||
|
Loading…
Reference in New Issue
Block a user