-
Notifications
You must be signed in to change notification settings - Fork 2
/
leg.go
40 lines (33 loc) · 854 Bytes
/
leg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package context
import (
"context"
"github.com/deixis/spine/contextutil"
)
// A Leg is a point-to-point request bounded by a process
type Leg interface {
UUID() string
ShortID() string
// Tick increments the stepper
Tick() uint
// Step returns a string representation of the current step
Step() Step
}
type legKey struct{}
var activeLegKey = legKey{}
// LegFromContext extracts `Leg` from context and returns `nil` when
// no instance of `Leg` can be found
func LegFromContext(ctx contextutil.ValueContext) Leg {
val := ctx.Value(activeLegKey)
if o, ok := val.(Leg); ok {
return o
}
val = ctx.Value(activeTransitKey)
if o, ok := val.(Leg); ok {
return o
}
return nil
}
// LegWithContext injects `Leg` to context
func LegWithContext(ctx context.Context, t Leg) context.Context {
return context.WithValue(ctx, activeLegKey, t)
}