From 17a82334cb3bf3ab59678d7df58dced67d0a1b6f Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 7 Jan 2025 00:37:34 +0100 Subject: [PATCH] http serializer --- evo.context.go | 12 ++++++++++++ lib/outcome/outcome.go | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/evo.context.go b/evo.context.go index 84e4fc9..b0d184f 100644 --- a/evo.context.go +++ b/evo.context.go @@ -159,6 +159,18 @@ func (r *Request) WriteResponse(resp ...any) { r.Write(v.Data) return } + if v, ok := instance.(outcome.HTTPSerializer); ok { + response := v.GetResponse() + r.WriteResponse(response) + return + } + if v, ok := instance.(*outcome.HTTPSerializer); ok { + if v != nil { + response := (*v).GetResponse() + r.WriteResponse(response) + return + } + } if v, ok := instance.(outcome.Response); ok { if v.StatusCode > 0 { diff --git a/lib/outcome/outcome.go b/lib/outcome/outcome.go index 3084db2..435c7a8 100644 --- a/lib/outcome/outcome.go +++ b/lib/outcome/outcome.go @@ -10,6 +10,10 @@ import ( "github.com/gofiber/fiber/v2" ) +type HTTPSerializer interface { + GetResponse() Response +} + type Response struct { ContentType string Data any