-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcontext.go
More file actions
34 lines (27 loc) · 830 Bytes
/
context.go
File metadata and controls
34 lines (27 loc) · 830 Bytes
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
package flow
import (
"context"
"github.com/antlinker/flow/expression"
)
type (
expKey struct{}
flagKey struct{}
)
// NewExpContext 创建表达式的上下文值
func NewExpContext(ctx context.Context, exp expression.ExpContext) context.Context {
return context.WithValue(ctx, expKey{}, exp)
}
// FromExpContext 获取表达式的上下文
func FromExpContext(ctx context.Context) (expression.ExpContext, bool) {
exp, ok := ctx.Value(expKey{}).(expression.ExpContext)
return exp, ok
}
// NewFlagContext 创建flag的上下文值
func NewFlagContext(ctx context.Context, flag string) context.Context {
return context.WithValue(ctx, flagKey{}, flag)
}
// FromFlagContext 获取flag的上下文
func FromFlagContext(ctx context.Context) (string, bool) {
flag, ok := ctx.Value(flagKey{}).(string)
return flag, ok
}