2020-04-29 16:21:46 +02:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
gocontext "context"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2020-04-29 23:10:06 +02:00
|
|
|
const KEY = "context_key"
|
2020-04-29 16:21:46 +02:00
|
|
|
|
2020-04-29 23:10:06 +02:00
|
|
|
type currentContextKey struct{}
|
2020-04-29 16:21:46 +02:00
|
|
|
|
2020-04-29 23:10:06 +02:00
|
|
|
func WithCurrentContext(ctx gocontext.Context, contextName string) context.Context {
|
|
|
|
return context.WithValue(ctx, currentContextKey{}, contextName)
|
2020-04-29 16:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentContext returns the current context name
|
|
|
|
func CurrentContext(ctx context.Context) string {
|
|
|
|
cc, _ := ctx.Value(currentContextKey{}).(string)
|
|
|
|
return cc
|
|
|
|
}
|