woodpecker/server/capability/context.go
2014-09-24 21:46:09 -07:00

33 lines
694 B
Go

package capability
import (
"code.google.com/p/go.net/context"
)
const reqkey = "capability"
// NewContext returns a Context whose Value method returns the
// application's Blobstore data.
func NewContext(parent context.Context, caps Capability) context.Context {
return &wrapper{parent, caps}
}
type wrapper struct {
context.Context
caps Capability
}
// Value returns the named key from the context.
func (c *wrapper) Value(key interface{}) interface{} {
if key == reqkey {
return c.caps
}
return c.Context.Value(key)
}
// FromContext returns the capability map for the
// current context.
func FromContext(c context.Context) Capability {
return c.Value(reqkey).(Capability)
}