diff options
author | Matt T. Proud <matt.proud@gmail.com> | 2021-02-25 01:03:35 +0100 |
---|---|---|
committer | Jean de Klerk <deklerk@google.com> | 2021-03-11 16:37:38 +0000 |
commit | 0fc370c5d26353a865a29a01f093942c949d530a (patch) | |
tree | 80c940f284e55c84cf49bba24fc9d273bd86ef64 /src/net/http/request.go | |
parent | b8e9ec856c2b2d717ab14e85f43e00b532c4370a (diff) | |
download | go-0fc370c5d26353a865a29a01f093942c949d530a.tar.gz go-0fc370c5d26353a865a29a01f093942c949d530a.zip |
docs: clarify when APIs use context.Background.
The Go standard library retrofitted context support onto existing APIs
using context.Background and later offered variants that directly
supported user-defined context value specification. This commit makes
that behavior clear in documentation and suggests context-aware
alternatives if the user is looking for one.
An example motivation is supporting code for use in systems that expect
APIs to be cancelable for lifecycle correctness or load
shedding/management reasons, as alluded to in
https://blog.golang.org/context-and-structs.
Updates #44143
Change-Id: I2d7f954ddf9b48264d5ebc8d0007058ff9bddf14
Reviewed-on: https://go-review.googlesource.com/c/go/+/296152
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Jean de Klerk <deklerk@google.com>
Trust: Jean de Klerk <deklerk@google.com>
Run-TryBot: Jean de Klerk <deklerk@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/net/http/request.go')
-rw-r--r-- | src/net/http/request.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/net/http/request.go b/src/net/http/request.go index adba5406e9..5251ebea66 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -823,7 +823,7 @@ func validMethod(method string) bool { return len(method) > 0 && strings.IndexFunc(method, isNotToken) == -1 } -// NewRequest wraps NewRequestWithContext using the background context. +// NewRequest wraps NewRequestWithContext using context.Background. func NewRequest(method, url string, body io.Reader) (*Request, error) { return NewRequestWithContext(context.Background(), method, url, body) } |