20 lines
570 B
Go
20 lines
570 B
Go
package routing
|
|
|
|
import "context"
|
|
|
|
type contextKey string
|
|
|
|
const sensitivityKey contextKey = "veylant.routing.sensitivity"
|
|
|
|
// WithSensitivity returns a new context carrying s.
|
|
func WithSensitivity(ctx context.Context, s Sensitivity) context.Context {
|
|
return context.WithValue(ctx, sensitivityKey, s)
|
|
}
|
|
|
|
// SensitivityFromContext retrieves the Sensitivity stored by WithSensitivity.
|
|
// Returns SensitivityNone and false if not set.
|
|
func SensitivityFromContext(ctx context.Context) (Sensitivity, bool) {
|
|
s, ok := ctx.Value(sensitivityKey).(Sensitivity)
|
|
return s, ok
|
|
}
|