Documentation
¶
Overview ¶
Package mesh provides the embeddable GopherMesh engine and launcher helpers used to load config, expose HTTP/TCP routes, bridge request-driven stdio workers in explicit stream/http modes, cold-start local backends, run the dashboard, and integrate the gophermesh:// desktop bootstrap flow. The launch protocol supports gophermesh://launch with optional port/conf query parameters.
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 ¶
- Constants
- func BuildHealthzPayload(options HealthzOptions) map[string]any
- func IsDashboardHealthy(cfg Config) bool
- func IsPublicRouteHealthy(port string) bool
- func RegisterLaunchProtocol() error
- func RegisterLaunchProtocolWithOptions(options LaunchProtocolOptions) error
- func ResolveLaunchConfigPath(defaultConfigPath, overrideConfigPath string) (string, error)
- func SaveConfig(path string, cfg Config) error
- func ValidateLaunchPort(cfg Config, port string) error
- func WriteHealthz(w http.ResponseWriter, options HealthzOptions)
- type BackendConfig
- type Config
- type Engine
- func (e *Engine) GetConfigJSON() []byte
- func (e *Engine) GetLogs(ref string) []string
- func (e *Engine) GetStatus() map[string]dashboard.RouteStatus
- func (e *Engine) KillProcess(ref 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 EngineOptions
- type HealthzOptions
- type LaunchProtocolOptions
- type LaunchProtocolRequest
- type LogBuffer
- type MeshEngine
- type ProcessInfo
- type Role
- type RouteConfig
Constants ¶
const DefaultHealthzVersion = "0.0.1"
DefaultHealthzVersion is used when callers do not specify a version.
const LaunchProtocolScheme = "gophermesh"
Variables ¶
This section is empty.
Functions ¶
func BuildHealthzPayload ¶ added in v1.4.0
func BuildHealthzPayload(options HealthzOptions) map[string]any
BuildHealthzPayload returns the canonical SDK health payload with optional custom fields appended. Reserved keys remain under SDK control.
func IsDashboardHealthy ¶ added in v1.2.0
func IsPublicRouteHealthy ¶ added in v1.2.0
func RegisterLaunchProtocol ¶ added in v1.2.0
func RegisterLaunchProtocol() error
func RegisterLaunchProtocolWithOptions ¶ added in v1.4.0
func RegisterLaunchProtocolWithOptions(options LaunchProtocolOptions) error
func ResolveLaunchConfigPath ¶ added in v1.2.0
func ValidateLaunchPort ¶ added in v1.2.0
func WriteHealthz ¶ added in v1.4.0
func WriteHealthz(w http.ResponseWriter, options HealthzOptions)
WriteHealthz writes the canonical SDK health payload as JSON.
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,omitempty"` // 目标进程实际监听的本地端口;stdio 路由下留空
}
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 EngineOptions ¶ added in v1.2.0
type EngineOptions struct {
NoDashboard bool
Healthz HealthzOptions
}
type HealthzOptions ¶ added in v1.4.0
HealthzOptions controls the payload returned by SDK health probes.
type LaunchProtocolOptions ¶ added in v1.4.0
type LaunchProtocolRequest ¶ added in v1.2.0
func HandleLaunchProtocol ¶ added in v1.2.0
func HandleLaunchProtocol(rawURL string, cfg Config) (LaunchProtocolRequest, error)
func ParseLaunchProtocol ¶ added in v1.2.0
func ParseLaunchProtocol(rawURL string) (LaunchProtocolRequest, error)
func ParseLaunchProtocolWithOptions ¶ added in v1.4.0
func ParseLaunchProtocolWithOptions(rawURL string, options LaunchProtocolOptions) (LaunchProtocolRequest, error)
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核心引擎的生命周期契约
func NewEngineWithOptions ¶ added in v1.2.0
func NewEngineWithOptions(cfg Config, opts EngineOptions) (MeshEngine, error)
NewEngineWithOptions 允许调用方覆盖 Dashboard 自动打开等运行行为。
type RouteConfig ¶
type RouteConfig struct {
Name string `json:"name"`
Protocol string `json:"protocol,omitempty"` // 默认为 http,可配置为 tcp / stdio
StdioMode string `json:"stdio_mode,omitempty"` // 仅 stdio 路由生效:stream / http / auto
LoadBalance string `json:"load_balance,omitempty"` // 支持 round_robin / least_conn / ip_hash
Backends []BackendConfig `json:"backends,omitempty"`
}
RouteConfig 定义单个对外暴露端口的路由规则。