version.go 586 B

1234567891011121314151617
  1. package context
  2. // WithVersion stores the application version in the context. The new context
  3. // gets a logger to ensure log messages are marked with the application
  4. // version.
  5. func WithVersion(ctx Context, version string) Context {
  6. ctx = WithValue(ctx, "version", version)
  7. // push a new logger onto the stack
  8. return WithLogger(ctx, GetLogger(ctx, "version"))
  9. }
  10. // GetVersion returns the application version from the context. An empty
  11. // string may returned if the version was not set on the context.
  12. func GetVersion(ctx Context) string {
  13. return GetStringValue(ctx, "version")
  14. }