-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathcontext_builder.go
54 lines (47 loc) · 1.77 KB
/
context_builder.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package ffcontext
// NewEvaluationContextBuilder constructs a new EvaluationContextBuilder, specifying the user targetingKey.
//
// For authenticated users, the targetingKey may be a username or e-mail address. For anonymous users,
// this could be an IP address or session ID.
func NewEvaluationContextBuilder(key string) EvaluationContextBuilder {
return &evaluationContextBuilderImpl{
key: key,
custom: map[string]interface{}{},
}
}
// EvaluationContextBuilder is a builder to create an EvaluationContext.
type EvaluationContextBuilder interface {
// Deprecated: Anonymous is to flag the context for an anonymous context or not.
// This function is here for compatibility reason, please consider to use AddCustom("anonymous", true)
// instead of using this function.
Anonymous(bool) EvaluationContextBuilder
AddCustom(string, interface{}) EvaluationContextBuilder
Build() EvaluationContext
}
type evaluationContextBuilderImpl struct {
// Key is the only mandatory attribute
key string
custom value
}
// Deprecated: Anonymous is to flag the context for an anonymous context or not.
// This function is here for compatibility reason, please consider using AddCustom("anonymous", true)
// instead of using this function.
func (u *evaluationContextBuilderImpl) Anonymous(anonymous bool) EvaluationContextBuilder {
u.custom["anonymous"] = anonymous
return u
}
// AddCustom allows you to add an attributes attribute to the EvaluationContext.
func (u *evaluationContextBuilderImpl) AddCustom(
key string,
value interface{},
) EvaluationContextBuilder {
u.custom[key] = value
return u
}
// Build is creating the EvaluationContext.
func (u *evaluationContextBuilderImpl) Build() EvaluationContext {
return EvaluationContext{
targetingKey: u.key,
attributes: u.custom,
}
}