env.go 376 B

1234567891011121314151617
  1. package envctx
  2. import "context"
  3. type environmentContextKey int
  4. const (
  5. environmentKey environmentContextKey = iota
  6. )
  7. func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context {
  8. return context.WithValue(ctx, environmentKey, environment)
  9. }
  10. func EnvironmentFromContext(ctx context.Context) interface{} {
  11. return ctx.Value(environmentKey)
  12. }