-
Notifications
You must be signed in to change notification settings - Fork 9
/
env.go
47 lines (38 loc) · 1.01 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package env
import "context"
// Environment is the type of the possible environment values.
type Environment string
// ConfigKey is the type of a config entry key.
type ConfigKey string
const (
// Production is the production environment.
Production Environment = "prod"
// QA is the qa environment.
QA Environment = "qa"
)
// Env is the value stored in context that stores the current environment along
// with configuration values.
type Env struct {
Environment Environment
Config map[ConfigKey]string
}
// ContextKey is the type of the key used with context to carry contextual
// environment.
type ContextKey string
const (
// envKey the context.Context key to store the env.
envKey ContextKey = "env.env"
)
// With stores the environment in the provided context.
func With(
ctx context.Context,
env *Env,
) context.Context {
return context.WithValue(ctx, envKey, env)
}
// Get returns the env currently stored in the context.
func Get(
ctx context.Context,
) *Env {
return ctx.Value(envKey).(*Env)
}