File size: 524 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package config

import "context"

type contextKey string

var contextKeyConfig = contextKey("config")

// Context returns a new Context that carries the provided Config.
func (cfg Config) Context(ctx context.Context) context.Context {
	return context.WithValue(ctx, contextKeyConfig, cfg)
}

// FromContext will return the Config carried in the provided Context.
//
// It panics if config is not available on the current context.
func FromContext(ctx context.Context) Config {
	return ctx.Value(contextKeyConfig).(Config)
}