RuleGo RuleGo
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Endpoint概述
  • 快速入门
  • 路由
  • DSL
  • API
    • Endpoint 接口
  • Options
  • 组件

目录

API

# Endpoint 接口 v0.21.0+

// Endpoint is an interface defining the basic structure of an endpoint in the rulego.
type Endpoint interface {
	types.Node
	// Id returns a unique identifier for the endpoint.
	Id() string
	// SetOnEvent sets the event listener function for the endpoint.
	SetOnEvent(onEvent OnEvent)
	// Start initiates the service.
	Start() error
	// AddInterceptors adds global interceptors to the endpoint.
	AddInterceptors(interceptors ...Process)
	// AddRouter adds a router with optional parameters and returns a router ID.
	// Some endpoints will return a new router ID, which needs to be updated with a new router ID
	AddRouter(router Router, params ...interface{}) (string, error)
	// RemoveRouter removes a router by its ID with optional parameters.
	RemoveRouter(routerId string, params ...interface{}) error
}

// DynamicEndpoint is an interface for dynamically defining an endpoint using a DSL (`types.EndpointDsl`).
type DynamicEndpoint interface {
	Endpoint
	SetId(id string)
	// SetConfig sets the configuration for the dynamic endpoint.
	SetConfig(config types.Config)
	// SetRouterOptions sets options for the router.
	SetRouterOptions(opts ...RouterOption)
	// SetRestart restart the endpoint.
	SetRestart(restart bool)
	// SetInterceptors sets the interceptors for the dynamic endpoint.
	SetInterceptors(interceptors ...Process)
	// Reload reloads the dynamic endpoint with a new DSL configuration.
	// If need to reload the endpoint, use `endpoint.DynamicEndpointOptions.WithRestart(true)`
	// Else the endpoint only update the route without restarting
	// Routing conflict, endpoint must be restarted
	Reload(dsl []byte, opts ...DynamicEndpointOption) error
	// ReloadFromDef reloads the dynamic endpoint with a new DSL configuration.
	ReloadFromDef(def types.EndpointDsl, opts ...DynamicEndpointOption) error
	// AddOrReloadRouter reloads or add the router with a new DSL configuration.
	AddOrReloadRouter(dsl []byte, opts ...DynamicEndpointOption) error
	// Definition returns the DSL definition of the dynamic endpoint.
	Definition() types.EndpointDsl
	// DSL returns the DSL configuration of the dynamic endpoint.
	DSL() []byte
	// Target returns the target endpoint.
	Target() Endpoint
}
// Factory is an interface defining that creates Endpoints.
type Factory interface {
// NewFromDsl creates a new DynamicEndpoint instance from DSL.
NewFromDsl(dsl []byte, opts ...DynamicEndpointOption) (DynamicEndpoint, error)
// NewFromDef creates a new DynamicEndpoint instance from DSL.
NewFromDef(def types.EndpointDsl, opts ...DynamicEndpointOption) (DynamicEndpoint, error)
// NewFromType creates a new Endpoint instance from type.
NewFromType(componentType string, ruleConfig types.Config, configuration interface{}) (Endpoint, error)
}

// Pool is an interface defining operations for managing a pool of endpoints.
type Pool interface {
// New creates a new dynamic endpoint.
New(id string, del []byte, opts ...DynamicEndpointOption) (DynamicEndpoint, error)
// Get retrieves a dynamic endpoint by its ID.
Get(id string) (DynamicEndpoint, bool)
// Del removes a dynamic endpoint instance by its ID.
Del(id string)
// Stop releases all dynamic endpoint instances.
Stop()
// Reload reloads all dynamic endpoint instances.
Reload(opts ...DynamicEndpointOption)
// Range iterates over all dynamic endpoint instances.
Range(f func(key, value any) bool)
// Factory returns the factory used to create endpoint instances.
Factory() Factory
}
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
在 GitHub 上编辑此页 (opens new window)
上次更新: 2025/03/31, 01:52:11
DSL
Options

← DSL Options→

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

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