diff --git a/exerr/data.go b/exerr/data.go index a35f7e7..e42135e 100644 --- a/exerr/data.go +++ b/exerr/data.go @@ -47,6 +47,7 @@ var ( TypeBindFailQuery = ErrorType{"BINDFAIL_QUERY", langext.Ptr(400)} TypeBindFailJSON = ErrorType{"BINDFAIL_JSON", langext.Ptr(400)} TypeBindFailFormData = ErrorType{"BINDFAIL_FORMDATA", langext.Ptr(400)} + TypeBindFailHeader = ErrorType{"BINDFAIL_HEADER", langext.Ptr(400)} TypeUnauthorized = ErrorType{"UNAUTHORIZED", langext.Ptr(401)} TypeAuthFailed = ErrorType{"AUTH_FAILED", langext.Ptr(401)} diff --git a/ginext/preContext.go b/ginext/preContext.go index 660b374..ae94c88 100644 --- a/ginext/preContext.go +++ b/ginext/preContext.go @@ -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) diff --git a/goextVersion.go b/goextVersion.go index 22b3aa6..70cbce7 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.199" +const GoextVersion = "0.0.200" -const GoextVersionTimestamp = "2023-07-24T17:23:38+0200" +const GoextVersionTimestamp = "2023-07-24T17:42:18+0200"