-
Notifications
You must be signed in to change notification settings - Fork 18k
context: decide on naming convention for context key variables #15229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Naming convention? Context keys are based on types. |
The naming convention for well-known context key values we use. See https://go-review.googlesource.com/#/c/21829 as an example. |
I see. I'll suggest using |
Though we've often found it nicer to expose |
Are you talking about I'd prefer |
CL https://golang.org/cl/21829 mentions this issue. |
Fixes #12438 Updates #15229 (to decide context key variable naming convention) Change-Id: I3ba423e91b689e232143247d044495a12c97a7d2 Reviewed-on: https://go-review.googlesource.com/21829 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
CL https://golang.org/cl/22672 mentions this issue. |
…ved on This adds a context key named LocalAddrContextKey (for now, see #15229) to let users access the net.Addr of the net.Listener that accepted the connection that sent an HTTP request. This is similar to ServerContextKey which provides access to the *Server. (A Server may have multiple Listeners) Fixes #6732 Change-Id: I74296307b68aaaab8df7ad4a143e11b5227b5e62 Reviewed-on: https://go-review.googlesource.com/22672 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Brad seems to have gone with |
For exported context keys, FooKey or FooContextKey seem fine to me. But my personal preference is to encapsulate the key and provide foo.NewContext(ctx, val)/foo.FromContext(ctx) or pkg.ContextWithFoo(ctx, val)/pkg.FooFromContext(ctx). |
Before Go 1.7, let's be sure we're happy with the naming convention for context key values.
/cc @adg @Sajmani @dsymonds
The text was updated successfully, but these errors were encountered: