Options
# Endpoint options v0.21.0+
// RouterOption is a function type for setting options on routing components.
type RouterOption func(OptionsSetter) error
// RouterOptions holds the default router options.
var RouterOptions = routerOptions{}
type routerOptions struct {
}
// WithRuleGoFunc sets a function to dynamically retrieve the rule engine pool.
func (r routerOptions) WithRuleGoFunc(f func(exchange *Exchange) types.RuleEnginePool) RouterOption {
return func(re OptionsSetter) error {
re.SetRuleEnginePoolFunc(f)
return nil
}
}
// WithRuleGo sets the rule engine pool, defaulting to `rulego.DefaultPool`.
func (r routerOptions) WithRuleGo(ruleGo types.RuleEnginePool) RouterOption {
return func(re OptionsSetter) error {
re.SetRuleEnginePool(ruleGo)
return nil
}
}
// WithRuleConfig sets the rule engine configuration.
func (r routerOptions) WithRuleConfig(config types.Config) RouterOption {
return func(re OptionsSetter) error {
re.SetConfig(config)
return nil
}
}
// WithContextFunc sets the context function for the routing operation.
func (r routerOptions) WithContextFunc(f func(ctx context.Context, exchange *Exchange) context.Context) RouterOption {
return func(re OptionsSetter) error {
re.SetContextFunc(f)
return nil
}
}
func (r routerOptions) WithDefinition(def *types.RouterDsl) RouterOption {
return func(re OptionsSetter) error {
re.SetDefinition(def)
return nil
}
}
// DynamicEndpointOption is a function type for setting options on dynamic endpoints.
type DynamicEndpointOption func(DynamicEndpoint) error
// DynamicEndpointOptions holds the default dynamic endpoint options.
var DynamicEndpointOptions = dynamicEndpointOptions{}
type dynamicEndpointOptions struct {
}
// WithId sets the ID for the dynamic endpoint.
func (d dynamicEndpointOptions) WithId(id string) DynamicEndpointOption {
return func(re DynamicEndpoint) error {
re.SetId(id)
return nil
}
}
// WithConfig sets the configuration for the dynamic endpoint.
func (d dynamicEndpointOptions) WithConfig(config types.Config) DynamicEndpointOption {
return func(re DynamicEndpoint) error {
re.SetConfig(config)
return nil
}
}
// WithRouterOpts sets the routerOptions for the dynamic endpoint.
func (d dynamicEndpointOptions) WithRouterOpts(opts ...RouterOption) DynamicEndpointOption {
return func(re DynamicEndpoint) error {
re.SetRouterOptions(opts...)
return nil
}
}
// WithOnEvent sets the event handler for the dynamic endpoint.
func (d dynamicEndpointOptions) WithOnEvent(onEvent OnEvent) DynamicEndpointOption {
return func(re DynamicEndpoint) error {
re.SetOnEvent(onEvent)
return nil
}
}
// WithRestart sets restart sign for the dynamic endpoint.
func (d dynamicEndpointOptions) WithRestart(restart bool) DynamicEndpointOption {
return func(re DynamicEndpoint) error {
re.SetRestart(restart)
return nil
}
}
// WithInterceptors sets the interceptors for the dynamic endpoint.
func (d dynamicEndpointOptions) WithInterceptors(interceptors ...Process) DynamicEndpointOption {
return func(re DynamicEndpoint) error {
re.SetInterceptors(interceptors...)
return nil
}
}
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
在 GitHub 上编辑此页 (opens new window)
上次更新: 2024/10/23, 10:13:01