mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
33 lines
694 B
Go
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)
|
||
|
}
|