This commit is contained in:
2023-07-24 17:42:18 +02:00
parent adf32568ee
commit a259bb6dbc
3 changed files with 19 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ type PreContext struct {
query any
body any
form any
header any
}
func (pctx *PreContext) URI(uri any) *PreContext {
@@ -39,6 +40,11 @@ func (pctx *PreContext) Form(form any) *PreContext {
return pctx
}
func (pctx *PreContext) Header(header any) *PreContext {
pctx.header = header
return pctx
}
func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
if pctx.uri != nil {
if err := pctx.ginCtx.ShouldBindUri(pctx.uri); err != nil {
@@ -94,6 +100,16 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
}
}
if pctx.header != nil {
if err := pctx.ginCtx.ShouldBindHeader(pctx.query); err != nil {
err = exerr.Wrap(err, "Failed to read header").
WithType(exerr.TypeBindFailHeader).
Str("struct_type", fmt.Sprintf("%T", pctx.query)).
Build()
return nil, nil, langext.Ptr(APIError(pctx.ginCtx, err))
}
}
ictx, cancel := context.WithTimeout(context.Background(), pctx.wrapper.requestTimeout)
actx := CreateAppContext(pctx.ginCtx, ictx, cancel)