Skip to content

Commit

Permalink
add context data in request
Browse files Browse the repository at this point in the history
  • Loading branch information
RonaldinhoL committed May 27, 2024
1 parent 384ff51 commit 1acc98e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Request struct {
dumpBuffer *bytes.Buffer
responseReturnTime time.Time
afterResponse []ResponseMiddleware
contextData map[string]any
}

type GetContentFunc func() (io.ReadCloser, error)
Expand Down Expand Up @@ -1207,3 +1208,18 @@ func (r *Request) EnableCloseConnection() *Request {
r.close = true
return r
}

func (r *Request) SetContextData(k string, v any) *Request {
if r.contextData == nil {
r.contextData = make(map[string]any)
}
r.contextData[k] = v
return r
}

func (r *Request) GetContextData(k string) any {
if r.contextData == nil {
return nil
}
return r.contextData[k]
}

0 comments on commit 1acc98e

Please sign in to comment.