v0.0.239 pctx.WithTImeout

This commit is contained in:
2023-08-11 16:32:34 +02:00
parent 0da098e9f9
commit 56094b3cb6
4 changed files with 13 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import (
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"runtime/debug"
"time"
)
type PreContext struct {
@@ -18,6 +19,7 @@ type PreContext struct {
body any
form any
header any
timeout *time.Duration
}
func (pctx *PreContext) URI(uri any) *PreContext {
@@ -45,6 +47,11 @@ func (pctx *PreContext) Header(header any) *PreContext {
return pctx
}
func (pctx *PreContext) WithTimeout(to time.Duration) *PreContext {
pctx.timeout = &to
return pctx
}
func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
if pctx.uri != nil {
if err := pctx.ginCtx.ShouldBindUri(pctx.uri); err != nil {
@@ -118,7 +125,7 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
}
}
ictx, cancel := context.WithTimeout(context.Background(), pctx.wrapper.requestTimeout)
ictx, cancel := context.WithTimeout(context.Background(), langext.Coalesce(pctx.timeout, pctx.wrapper.requestTimeout))
actx := CreateAppContext(pctx.ginCtx, ictx, cancel)
return actx, pctx.ginCtx, nil