-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule.go
59 lines (47 loc) · 1.11 KB
/
rule.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
55
56
57
58
59
package golidate
type Rule func(value any) Result
type Rules []Rule
func (rule Rule) Code(code string) Rule {
return func(value any) Result {
result := rule(value)
result.Code = code
return result
}
}
func (rule Rule) Message(message string) Rule {
return func(value any) Result {
result := rule(value)
result.Message = message
return result
}
}
func (rule Rule) Rename(code string) Rule {
return rule.
Code(code).
Message(code)
}
func (rule Rule) With(key string, val any) Rule {
return func(value any) Result {
return rule(value).With(key, val)
}
}
func (rule Rule) Conditions(conditions ...Condition) Rule {
return func(value any) Result {
return rule(value).Conditions(conditions...)
}
}
func (rule Rule) When(condition bool) Rule {
return func(value any) Result {
return rule(value).When(condition)
}
}
func (rule Rule) WithMetadata(metadata Metadata) Rule {
return func(value any) Result {
return rule(value).WithMetadata(metadata)
}
}
func (rule Rule) WithMetadataMerged(metadata Metadata) Rule {
return func(value any) Result {
return rule(value).WithMetadataMerged(metadata)
}
}