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

Commit b31e65b

Browse files
committed
Add setter for Context
In d9259e3 a getter was added for the context, this adds a setter. cc @LucasRoesler Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent d9259e3 commit b31e65b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

handler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ func (r *Request) Context() context.Context {
3333
return r.ctx
3434
}
3535

36+
// WithContext overides the context for the Request struct
37+
func (r *Request) WithContext(ctx context.Context) {
38+
// AE: Not keen on panic mid-flow in user-code, however stdlib also appears to do
39+
// this. https://golang.org/src/net/http/request.go
40+
// This is not setting a precedent for broader use of "panic" to handle errors.
41+
if ctx == nil {
42+
panic("nil context")
43+
}
44+
r.ctx = ctx
45+
}
46+
3647
// FunctionHandler used for a serverless Go method invocation
3748
type FunctionHandler interface {
3849
Handle(req Request) (Response, error)

0 commit comments

Comments
 (0)