Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
sdk: add FromRequest() helper
Browse files Browse the repository at this point in the history
Add `sdk.FromRequest()` helper function to retrieve Sqreen's SDK handle from a request.
It is a shortcut to `sdk.FromContext(r.Context())`.
  • Loading branch information
Julio Guerra authored Nov 18, 2020
2 parents a0d8208 + 402e454 commit ded1fbb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func FromContext(ctx go_context.Context) Context {
return context{events: actual}
}

type Request interface {
Context() go_context.Context
}

// FromRequest is equivalent to `FromContext(r.Context())`
func FromRequest(r Request) Context {
return FromContext(r.Context())
}

// TrackEvent allows to track a custom security events with the given event name.
// It creates a new event whose additional options can be set using the
// returned value's methods, such as `WithProperties()` or
Expand Down

0 comments on commit ded1fbb

Please sign in to comment.