mirror of
https://github.com/docker/compose.git
synced 2025-05-05 07:00:12 +02:00
* the interceptor takes the current context from the metadat * each handler needs to call `client.SetContext()` before using the sevices
22 lines
456 B
Go
22 lines
456 B
Go
package context
|
|
|
|
import (
|
|
gocontext "context"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
const KEY = "context_key"
|
|
|
|
type currentContextKey struct{}
|
|
|
|
func WithCurrentContext(ctx gocontext.Context, contextName string) context.Context {
|
|
return context.WithValue(ctx, currentContextKey{}, contextName)
|
|
}
|
|
|
|
// CurrentContext returns the current context name
|
|
func CurrentContext(ctx context.Context) string {
|
|
cc, _ := ctx.Value(currentContextKey{}).(string)
|
|
return cc
|
|
}
|