RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

    • Endpoint Overview
    • Quick Start
    • Router
    • DSL
    • API
    • Options
      • Endpoint options
    • Endpoints

  • Support

目录

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
Edit this page on GitHub (opens new window)
Last Updated: 2025/04/02, 01:29:50
API
Rest Endpoint

← API Rest Endpoint→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式