-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2360 from stevvooe/remove-context-type
context: remove definition of Context
- Loading branch information
Showing
90 changed files
with
396 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
package context | ||
|
||
import "context" | ||
|
||
type versionKey struct{} | ||
|
||
func (versionKey) String() string { return "version" } | ||
|
||
// WithVersion stores the application version in the context. The new context | ||
// gets a logger to ensure log messages are marked with the application | ||
// version. | ||
func WithVersion(ctx Context, version string) Context { | ||
ctx = WithValue(ctx, "version", version) | ||
func WithVersion(ctx context.Context, version string) context.Context { | ||
ctx = context.WithValue(ctx, versionKey{}, version) | ||
// push a new logger onto the stack | ||
return WithLogger(ctx, GetLogger(ctx, "version")) | ||
return WithLogger(ctx, GetLogger(ctx, versionKey{})) | ||
} | ||
|
||
// GetVersion returns the application version from the context. An empty | ||
// string may returned if the version was not set on the context. | ||
func GetVersion(ctx Context) string { | ||
return GetStringValue(ctx, "version") | ||
func GetVersion(ctx context.Context) string { | ||
return GetStringValue(ctx, versionKey{}) | ||
} |
Oops, something went wrong.