1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/server/worker/context.go
2014-09-28 18:36:24 -07:00

32 lines
676 B
Go

package worker
import (
"code.google.com/p/go.net/context"
)
const reqkey = "worker"
// NewContext returns a Context whose Value method returns the
// application's worker queue.
func NewContext(parent context.Context, worker Worker) context.Context {
return &wrapper{parent, worker}
}
type wrapper struct {
context.Context
worker Worker
}
// Value returns the named key from the context.
func (c *wrapper) Value(key interface{}) interface{} {
if key == reqkey {
return c.worker
}
return c.Context.Value(key)
}
// FromContext returns the worker queue associated with this context.
func FromContext(c context.Context) Worker {
return c.Value(reqkey).(Worker)
}