2020-12-07 16:10:20 +03:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type configKey struct{}
|
|
|
|
|
2021-02-13 15:35:56 +03:00
|
|
|
// FromContext returns store from context
|
2020-12-07 16:10:20 +03:00
|
|
|
func FromContext(ctx context.Context) (Config, bool) {
|
2020-12-17 22:52:00 +03:00
|
|
|
if ctx == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
2020-12-07 16:10:20 +03:00
|
|
|
c, ok := ctx.Value(configKey{}).(Config)
|
|
|
|
return c, ok
|
|
|
|
}
|
|
|
|
|
2021-02-13 15:35:56 +03:00
|
|
|
// NewContext put store in context
|
2020-12-07 16:10:20 +03:00
|
|
|
func NewContext(ctx context.Context, c Config) context.Context {
|
2020-12-17 22:52:00 +03:00
|
|
|
if ctx == nil {
|
|
|
|
ctx = context.Background()
|
|
|
|
}
|
2020-12-07 16:10:20 +03:00
|
|
|
return context.WithValue(ctx, configKey{}, c)
|
|
|
|
}
|