-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathuser_builder.go
50 lines (44 loc) · 1.28 KB
/
user_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
package ffuser
// Deprecated: NewUserBuilder, please use ffcontext.NewEvaluationContextBuilder instead.
//
// NewUserBuilder constructs a new UserBuilder, specifying the user key.
//
// For authenticated users, the key may be a username or e-mail address. For anonymous users,
// this could be an IP address or session ID.
func NewUserBuilder(key string) UserBuilder {
return &userBuilderImpl{
key: key,
custom: map[string]interface{}{},
}
}
// Deprecated: UserBuilder, please use ffcontext.EvaluationContextBuilder instead.
//
// UserBuilder is a builder to create a User.
type UserBuilder interface {
Anonymous(bool) UserBuilder
AddCustom(string, interface{}) UserBuilder
Build() User
}
type userBuilderImpl struct {
key string // only mandatory attribute
anonymous bool
custom value
}
// Anonymous is to set the user as anonymous.
func (u *userBuilderImpl) Anonymous(anonymous bool) UserBuilder {
u.anonymous = anonymous
return u
}
// AddCustom allows you to add a custom attribute to the user.
func (u *userBuilderImpl) AddCustom(key string, value interface{}) UserBuilder {
u.custom[key] = value
return u
}
// Build is creating the user.
func (u *userBuilderImpl) Build() User {
return User{
key: u.key,
anonymous: u.anonymous,
custom: u.custom,
}
}