2017-07-11 17:12:12 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
type contextKeyT string
|
|
|
|
|
2017-07-14 18:05:54 +00:00
|
|
|
var contextKey = contextKeyT("buildkit/session-id")
|
2017-07-11 17:12:12 +00:00
|
|
|
|
2017-07-14 18:05:54 +00:00
|
|
|
func NewContext(ctx context.Context, id string) context.Context {
|
|
|
|
if id != "" {
|
|
|
|
return context.WithValue(ctx, contextKey, id)
|
2017-07-11 17:12:12 +00:00
|
|
|
}
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromContext(ctx context.Context) string {
|
|
|
|
v := ctx.Value(contextKey)
|
|
|
|
if v == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return v.(string)
|
|
|
|
}
|