21 lines
447 B
Go
Raw Normal View History

2021-09-05 15:36:57 +01:00
package envctx
import "context"
type environmentContextKey int
const (
environmentKey environmentContextKey = iota
)
func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context {
return context.WithValue(ctx, environmentKey, environment)
}
func EnvironmentFromContext(ctx context.Context) interface{} {
if environment, ok := ctx.Value(environmentKey).(interface{}); ok {
return environment
}
return nil
}