2016-04-13 02:27:24 +02:00
|
|
|
package stream
|
|
|
|
|
|
|
|
import "golang.org/x/net/context"
|
|
|
|
|
|
|
|
const key = "stream"
|
|
|
|
|
|
|
|
// Setter defines a context that enables setting values.
|
|
|
|
type Setter interface {
|
|
|
|
Set(string, interface{})
|
|
|
|
}
|
|
|
|
|
2016-04-23 02:35:32 +02:00
|
|
|
// FromContext returns the Stream associated with this context.
|
|
|
|
func FromContext(c context.Context) Stream {
|
|
|
|
return c.Value(key).(Stream)
|
2016-04-13 02:27:24 +02:00
|
|
|
}
|
|
|
|
|
2016-04-23 02:35:32 +02:00
|
|
|
// ToContext adds the Stream to this context if it supports the
|
|
|
|
// Setter interface.
|
|
|
|
func ToContext(c Setter, s Stream) {
|
|
|
|
c.Set(key, s)
|
2016-04-13 02:27:24 +02:00
|
|
|
}
|