mirror of
https://github.com/distribution/distribution
synced 2024-11-12 05:45:51 +01:00
530afa5234
By adding WithVersion to the context package, we can simplify context setup in the application. This avoids some odd bugs where instantiation order can lead to missing instance.id or version from log messages. Signed-off-by: Stephen J Day <stephen.day@docker.com>
17 lines
586 B
Go
17 lines
586 B
Go
package context
|
|
|
|
// 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)
|
|
// push a new logger onto the stack
|
|
return WithLogger(ctx, GetLogger(ctx, "version"))
|
|
}
|
|
|
|
// 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")
|
|
}
|