v0.0.326 ginext::WithSession
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m38s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m38s
This commit is contained in:
@@ -15,15 +15,20 @@ import (
|
||||
)
|
||||
|
||||
type PreContext struct {
|
||||
ginCtx *gin.Context
|
||||
wrapper *GinWrapper
|
||||
uri any
|
||||
query any
|
||||
body any
|
||||
rawbody *[]byte
|
||||
form any
|
||||
header any
|
||||
timeout *time.Duration
|
||||
ginCtx *gin.Context
|
||||
wrapper *GinWrapper
|
||||
uri any
|
||||
query any
|
||||
body any
|
||||
rawbody *[]byte
|
||||
form any
|
||||
header any
|
||||
timeout *time.Duration
|
||||
persistantData *preContextData // must be a ptr, so that we can get the values back in out Wrap func
|
||||
}
|
||||
|
||||
type preContextData struct {
|
||||
sessionObj SessionObject
|
||||
}
|
||||
|
||||
func (pctx *PreContext) URI(uri any) *PreContext {
|
||||
@@ -61,6 +66,11 @@ func (pctx *PreContext) WithTimeout(to time.Duration) *PreContext {
|
||||
return pctx
|
||||
}
|
||||
|
||||
func (pctx *PreContext) WithSession(sessionObj SessionObject) *PreContext {
|
||||
pctx.persistantData.sessionObj = sessionObj
|
||||
return pctx
|
||||
}
|
||||
|
||||
func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
||||
if pctx.uri != nil {
|
||||
if err := pctx.ginCtx.ShouldBindUri(pctx.uri); err != nil {
|
||||
@@ -152,6 +162,15 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
||||
}
|
||||
|
||||
ictx, cancel := context.WithTimeout(context.Background(), langext.Coalesce(pctx.timeout, pctx.wrapper.requestTimeout))
|
||||
|
||||
if pctx.persistantData.sessionObj != nil {
|
||||
err := pctx.persistantData.sessionObj.Init(pctx.ginCtx, ictx)
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, nil, langext.Ptr(Error(exerr.Wrap(err, "Failed to init session").Build()))
|
||||
}
|
||||
}
|
||||
|
||||
actx := CreateAppContext(pctx.ginCtx, ictx, cancel)
|
||||
|
||||
return actx, pctx.ginCtx, nil
|
||||
|
Reference in New Issue
Block a user