1package config
2
3import "context"
4
5// ContextKey is the context key for the config.
6var ContextKey = struct{ string }{"config"}
7
8// WithContext returns a new context with the configuration attached.
9func WithContext(ctx context.Context, cfg *Config) context.Context {
10 return context.WithValue(ctx, ContextKey, cfg)
11}
12
13// FromContext returns the configuration from the context.
14func FromContext(ctx context.Context) *Config {
15 if c, ok := ctx.Value(ContextKey).(*Config); ok {
16 return c
17 }
18
19 return nil
20}