...
1 package context
2
3 import (
4 "context"
5
6 "github.com/redhat-developer/odo/pkg/config"
7 )
8
9 type contextKey struct{}
10
11 var key = contextKey{}
12
13
14 func WithEnvConfig(ctx context.Context, val config.Configuration) context.Context {
15 return context.WithValue(ctx, key, val)
16 }
17
18
19 func GetEnvConfig(ctx context.Context) config.Configuration {
20 value := ctx.Value(key)
21 if cast, ok := value.(config.Configuration); ok {
22 return cast
23 }
24 panic("GetEnvConfig can be called only after WithEnvConfig has been called")
25 }
26
View as plain text