Skip to content

Commit

Permalink
Added SetCacheControl to Outcome.
Browse files Browse the repository at this point in the history
Removed unused code from SetCacheControl in evo.context.
  • Loading branch information
Davide bonomini committed Dec 18, 2023
1 parent 7f1f3e2 commit a975e1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 0 additions & 4 deletions evo.context.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ func (r *Request) RestartRouting() error {
}

func (r *Request) SetCacheControl(t time.Duration, headers ...string) {
if len(headers) == 0 {
return
}

var ccHeader string = fmt.Sprintf("max-age=%.0f", t.Seconds())
var options string

Expand Down
21 changes: 20 additions & 1 deletion lib/outcome/outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"reflect"
"time"

"github.com/gofiber/fiber/v2"
)

type Response struct {
Expand Down Expand Up @@ -185,3 +186,21 @@ func (response *Response) Filename(filename string) *Response {
func (response *Response) ResponseSerializer() *Response {
return response
}

func (response *Response) SetCacheControl(t time.Duration, headers ...string) *Response {
var ccHeader string = fmt.Sprintf("max-age=%.0f", t.Seconds())
var options string

for _, header := range headers {
options = options + fmt.Sprintf(", %s", header)
}

ccHeader = ccHeader + options

if response.Headers == nil {
response.Headers = map[string]string{}
}
response.Headers["Cache-Control"] = ccHeader

return response
}

0 comments on commit a975e1a

Please sign in to comment.