Documentation
¶
Overview ¶
Package mesh provides the embeddable GopherMesh engine used to load config, expose HTTP/TCP routes, cold-start local backends, and run the dashboard.
The recommended integration order is:
- Start with CLI + config.json when you only need routing and process orchestration.
- Use this package when you need to embed GopherMesh into a custom Go launcher.
This package currently implements the single-node gateway/runtime model. It should not be described as a full distributed service mesh.
Index ¶
- func SaveConfig(path string, cfg Config) error
- type BackendConfig
- type Config
- type Engine
- func (e *Engine) GetConfigJSON() []byte
- func (e *Engine) GetLogs(port string) []string
- func (e *Engine) GetStatus() map[string]dashboard.RouteStatus
- func (e *Engine) KillProcess(port string) error
- func (e *Engine) ReloadConfig(rawJSON []byte) error
- func (e *Engine) Role() Role
- func (e *Engine) Run(ctx context.Context) error
- func (e *Engine) Shutdown(ctx context.Context) error
- type LogBuffer
- type MeshEngine
- type ProcessInfo
- type Role
- type RouteConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackendConfig ¶
type BackendConfig struct {
Name string `json:"name,omitempty"`
Cmd string `json:"cmd"` // 执行的二进制目标,为空或"internal"表示内部路由
Args []string `json:"args,omitempty"` // 启动参数
InternalHost string `json:"internal_host,omitempty"` // 目标主机IP/域名
InternalPort string `json:"internal_port"` // 目标进程实际监听的本地端口
}
BackendConfig 定义路由下单个实际承载请求的后端。
type Config ¶
type Config struct {
ConfigPath string `json:"-"`
DashboardHost string `json:"dashboard_host"`
DashboardPort string `json:"dashboard_port"`
TrustedOrigins []string `json:"trusted_origins"`
ServiceName string `json:"service_name,omitempty"`
InternalPort string `json:"internal_port,omitempty"`
Routes map[string]RouteConfig `json:"routes,omitempty"`
}
Config 代表 GopherMesh 全局配置(支持无头静默运行)
func LoadConfig ¶
LoadConfig 从指定路径加载配置,若文件不存在则初始化默认配置并落盘
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 是 MeshEngine 接口的具体实现
func (*Engine) GetConfigJSON ¶
GetConfigJSON 返回当前 Routes 的 JSON 字符串
func (*Engine) GetStatus ¶
func (e *Engine) GetStatus() map[string]dashboard.RouteStatus
GetStatus 实现 dashboard.MeshState 接口,收集底层进程快照
func (*Engine) KillProcess ¶
KillProcess 实现 dashboard.MeshState 接口,支持手动kill底层进程
func (*Engine) ReloadConfig ¶
ReloadConfig 接收前端传来的新 JSON,验证、落盘、并执行平滑重载
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
LogBuffer 是一个并发安全的行级环形缓冲区,实现了 io.Writer 端口
type MeshEngine ¶
type MeshEngine interface {
// Role 返回当前实例运行的身份
Role() Role
// Run 启动代理或注册工作节点,并阻塞直到ctx被取消
Run(ctx context.Context) error
// Shutdown 触发安全退出,释放端口并优雅中介所有托管的子进程
Shutdown(ctx context.Context) error
}
MeshEngine 定义了GopherMesh核心引擎的生命周期契约
type RouteConfig ¶
type RouteConfig struct {
Name string `json:"name"`
Protocol string `json:"protocol,omitempty"` // 默认为 http,可配置为 tcp
LoadBalance string `json:"load_balance,omitempty"` // 支持 round_robin / least_conn / ip_hash
Backends []BackendConfig `json:"backends,omitempty"`
}
RouteConfig 定义单个对外暴露端口的路由规则。