context.go 620 B

123456789101112131415161718192021222324
  1. package context
  2. import (
  3. gocontext "context"
  4. "golang.org/x/net/context"
  5. )
  6. // Key is the key where the current docker context is stored in the metadata
  7. // of a gRPC request
  8. const Key = "context_key"
  9. type currentContextKey struct{}
  10. // WithCurrentContext sets the name of the current docker context
  11. func WithCurrentContext(ctx gocontext.Context, contextName string) context.Context {
  12. return context.WithValue(ctx, currentContextKey{}, contextName)
  13. }
  14. // CurrentContext returns the current context name
  15. func CurrentContext(ctx context.Context) string {
  16. cc, _ := ctx.Value(currentContextKey{}).(string)
  17. return cc
  18. }