1
0
mirror of https://github.com/golang/go synced 2024-11-25 10:57:58 -07:00

context: link to context and structs blog post

This commit amends the package documentation for the context package
and links the https://go.dev/blog/context-and-structs where the package
documentation dissuades one against embedding a context into a struct.
This is to help close the gap in understanding why this otherwise
cryptic piece of guidance is provided. The other referenced blog
article now points to go.dev instead of golang.org.

Change-Id: I0844a57bde1c03b6dddd1dd2dab2d20557d791fb
GitHub-Last-Rev: 4b039fba90
GitHub-Pull-Request: golang/go#69696
Reviewed-on: https://go-review.googlesource.com/c/go/+/616515
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Matt T. Proud 2024-09-29 05:23:33 +00:00 committed by Gopher Robot
parent aec9b916a2
commit 7f87b82955

View File

@ -33,7 +33,8 @@
// propagation:
//
// Do not store Contexts inside a struct type; instead, pass a Context
// explicitly to each function that needs it. The Context should be the first
// explicitly to each function that needs it. This is discussed further in
// https://go.dev/blog/context-and-structs. The Context should be the first
// parameter, typically named ctx:
//
// func DoSomething(ctx context.Context, arg Arg) error {
@ -49,7 +50,7 @@
// The same Context may be passed to functions running in different goroutines;
// Contexts are safe for simultaneous use by multiple goroutines.
//
// See https://blog.golang.org/context for example code for a server that uses
// See https://go.dev/blog/context for example code for a server that uses
// Contexts.
package context