Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
55d02b8c65
|
|||
8a3965f666
|
@@ -39,7 +39,7 @@ func Wrap(w *GinWrapper, fn WHandlerFunc) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if pctx.persistantData.sessionObj != nil {
|
||||
err := pctx.persistantData.sessionObj.Finish(reqctx, wrap)
|
||||
err := (*pctx.persistantData.sessionObj).Finish(reqctx, wrap)
|
||||
if err != nil {
|
||||
wrap = Error(exerr.Wrap(err, "Failed to finish session").Any("originalResponse", wrap).Build())
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ type PreContext struct {
|
||||
}
|
||||
|
||||
type preContextData struct {
|
||||
sessionObj SessionObject
|
||||
sessionObj *SessionObject
|
||||
}
|
||||
|
||||
func (pctx *PreContext) URI(uri any) *PreContext {
|
||||
@@ -67,7 +67,7 @@ func (pctx *PreContext) WithTimeout(to time.Duration) *PreContext {
|
||||
}
|
||||
|
||||
func (pctx *PreContext) WithSession(sessionObj SessionObject) *PreContext {
|
||||
pctx.persistantData.sessionObj = sessionObj
|
||||
pctx.persistantData.sessionObj = &sessionObj
|
||||
return pctx
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ 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)
|
||||
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()))
|
||||
|
@@ -15,6 +15,7 @@ type headerval struct {
|
||||
type HTTPResponse interface {
|
||||
Write(g *gin.Context)
|
||||
WithHeader(k string, v string) HTTPResponse
|
||||
IsSuccess() bool
|
||||
}
|
||||
|
||||
type jsonHTTPResponse struct {
|
||||
@@ -39,6 +40,10 @@ func (j jsonHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j jsonHTTPResponse) IsSuccess() bool {
|
||||
return j.statusCode >= 200 && j.statusCode <= 399
|
||||
}
|
||||
|
||||
type emptyHTTPResponse struct {
|
||||
statusCode int
|
||||
headers []headerval
|
||||
@@ -56,6 +61,10 @@ func (j emptyHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j emptyHTTPResponse) IsSuccess() bool {
|
||||
return j.statusCode >= 200 && j.statusCode <= 399
|
||||
}
|
||||
|
||||
type textHTTPResponse struct {
|
||||
statusCode int
|
||||
data string
|
||||
@@ -74,6 +83,10 @@ func (j textHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j textHTTPResponse) IsSuccess() bool {
|
||||
return j.statusCode >= 200 && j.statusCode <= 399
|
||||
}
|
||||
|
||||
type dataHTTPResponse struct {
|
||||
statusCode int
|
||||
data []byte
|
||||
@@ -93,6 +106,10 @@ func (j dataHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j dataHTTPResponse) IsSuccess() bool {
|
||||
return j.statusCode >= 200 && j.statusCode <= 399
|
||||
}
|
||||
|
||||
type fileHTTPResponse struct {
|
||||
mimetype string
|
||||
filepath string
|
||||
@@ -117,6 +134,10 @@ func (j fileHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j fileHTTPResponse) IsSuccess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type downloadDataHTTPResponse struct {
|
||||
statusCode int
|
||||
mimetype string
|
||||
@@ -142,6 +163,10 @@ func (j downloadDataHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j downloadDataHTTPResponse) IsSuccess() bool {
|
||||
return j.statusCode >= 200 && j.statusCode <= 399
|
||||
}
|
||||
|
||||
type redirectHTTPResponse struct {
|
||||
statusCode int
|
||||
url string
|
||||
@@ -157,6 +182,10 @@ func (j redirectHTTPResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j redirectHTTPResponse) IsSuccess() bool {
|
||||
return j.statusCode >= 200 && j.statusCode <= 399
|
||||
}
|
||||
|
||||
type jsonAPIErrResponse struct {
|
||||
err *exerr.ExErr
|
||||
headers []headerval
|
||||
@@ -171,6 +200,10 @@ func (j jsonAPIErrResponse) WithHeader(k string, v string) HTTPResponse {
|
||||
return j
|
||||
}
|
||||
|
||||
func (j jsonAPIErrResponse) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func Status(sc int) HTTPResponse {
|
||||
return &emptyHTTPResponse{statusCode: sc}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.326"
|
||||
const GoextVersion = "0.0.328"
|
||||
|
||||
const GoextVersionTimestamp = "2023-12-02T13:07:36+0100"
|
||||
const GoextVersionTimestamp = "2023-12-02T13:35:18+0100"
|
||||
|
Reference in New Issue
Block a user