2016-04-13 00:27:24 +00: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 00:35:32 +00:00
|
|
|
// FromContext returns the Stream associated with this context.
|
|
|
|
func FromContext(c context.Context) Stream {
|
|
|
|
return c.Value(key).(Stream)
|
2016-04-13 00:27:24 +00:00
|
|
|
}
|
|
|
|
|
2016-04-23 00:35:32 +00: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 00:27:24 +00:00
|
|
|
}
|