v0.0.200
This commit is contained in:
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user