Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Add setter for Context
Browse files Browse the repository at this point in the history
In d9259e3 a getter was added
for the context, this adds a setter.

cc @LucasRoesler

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Apr 5, 2020
1 parent d9259e3 commit b31e65b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ func (r *Request) Context() context.Context {
return r.ctx
}

// WithContext overides the context for the Request struct
func (r *Request) WithContext(ctx context.Context) {
// AE: Not keen on panic mid-flow in user-code, however stdlib also appears to do
// this. https://golang.org/src/net/http/request.go
// This is not setting a precedent for broader use of "panic" to handle errors.
if ctx == nil {
panic("nil context")
}
r.ctx = ctx
}

// FunctionHandler used for a serverless Go method invocation
type FunctionHandler interface {
Handle(req Request) (Response, error)
Expand Down

0 comments on commit b31e65b

Please sign in to comment.