diff --git a/extra/fuegogin/adaptor.go b/extra/fuegogin/adaptor.go index 334034c4..76ff9bfe 100644 --- a/extra/fuegogin/adaptor.go +++ b/extra/fuegogin/adaptor.go @@ -64,19 +64,7 @@ func GinHandler[B, T any](engine *fuego.Engine, handler func(c fuego.ContextWith ginCtx: c, } - resp, err := handler(context) - if err != nil { - err = engine.ErrorHandler(err) - c.JSON(getErrorCode(err), err) - return - } - - if c.Request.Header.Get("Accept") == "application/xml" { - c.XML(200, resp) - return - } - - c.JSON(200, resp) + fuego.Flow(engine, context, handler) } } diff --git a/extra/fuegogin/context.go b/extra/fuegogin/context.go index 0d04d0c9..cda8442d 100644 --- a/extra/fuegogin/context.go +++ b/extra/fuegogin/context.go @@ -17,6 +17,7 @@ type ginContext[B any] struct { } var _ fuego.ContextWithBody[any] = &ginContext[any]{} +var _ fuego.ContextFlowable[any] = &ginContext[any]{} func (c ginContext[B]) Body() (B, error) { var body B @@ -77,6 +78,16 @@ func (c ginContext[B]) SetCookie(cookie http.Cookie) { c.ginCtx.SetCookie(cookie.Name, cookie.Value, cookie.MaxAge, cookie.Path, cookie.Domain, cookie.Secure, cookie.HttpOnly) } +func (c ginContext[B]) HasCookie(name string) bool { + _, err := c.Cookie(name) + return err == nil +} + +func (c ginContext[B]) HasHeader(key string) bool { + _, ok := c.ginCtx.Request.Header[key] + return ok +} + func (c ginContext[B]) SetHeader(key, value string) { c.ginCtx.Header(key, value) } @@ -84,3 +95,19 @@ func (c ginContext[B]) SetHeader(key, value string) { func (c ginContext[B]) SetStatus(code int) { c.ginCtx.Status(code) } + +func (c ginContext[B]) Serialize(data any) error { + c.ginCtx.JSON(http.StatusOK, data) + return nil +} + +func (c ginContext[B]) SerializeError(err error) { + c.ginCtx.JSON(http.StatusInternalServerError, err) +} + +func (c ginContext[B]) SetDefaultStatusCode() { + if c.DefaultStatusCode == 0 { + c.DefaultStatusCode = http.StatusOK + } + c.SetStatus(c.DefaultStatusCode) +}