mirror of
				https://github.com/woodpecker-ci/woodpecker.git
				synced 2025-11-04 03:00:50 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			689 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			689 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package blobstore
 | 
						|
 | 
						|
import (
 | 
						|
	"code.google.com/p/go.net/context"
 | 
						|
)
 | 
						|
 | 
						|
const reqkey = "blobstore"
 | 
						|
 | 
						|
// NewContext returns a Context whose Value method returns the
 | 
						|
// application's Blobstore data.
 | 
						|
func NewContext(parent context.Context, store Blobstore) context.Context {
 | 
						|
	return &wrapper{parent, store}
 | 
						|
}
 | 
						|
 | 
						|
type wrapper struct {
 | 
						|
	context.Context
 | 
						|
	store Blobstore
 | 
						|
}
 | 
						|
 | 
						|
// Value returns the named key from the context.
 | 
						|
func (c *wrapper) Value(key interface{}) interface{} {
 | 
						|
	if key == reqkey {
 | 
						|
		return c.store
 | 
						|
	}
 | 
						|
	return c.Context.Value(key)
 | 
						|
}
 | 
						|
 | 
						|
// FromContext returns the Blobstore associated with this context.
 | 
						|
func FromContext(c context.Context) Blobstore {
 | 
						|
	return c.Value(reqkey).(Blobstore)
 | 
						|
}
 |