Documentation
¶
Overview ¶
Package module 定义功能模块的统一接口。
每个模块拥有独立的配置文件(config.Store 中以 ID 命名)、独立的日志缓冲, 以及挂载在 /api/<ID>/ 下的管理接口。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DocRouter ¶ added in v0.3.0
DocRouter 由支持接口文档的 Router 实现。模块可通过类型断言为接口补充文档信息, pattern 与 HandleFunc 的写法一致(相对模块前缀)。
type Module ¶
type Module interface {
// ID 是模块唯一标识,同时作为配置文件名和 API 前缀
ID() string
// Title 是界面显示名称
Title() string
// Init 加载配置,不启动任何网络服务
Init(env Env) error
// Start 按配置启动服务,ctx 在程序退出时取消
Start(ctx context.Context) error
// Stop 停止全部服务并释放端口
Stop() error
// Routes 注册管理接口
Routes(r Router)
}
Module 是所有功能模块需要实现的接口。
type Router ¶
type Router interface {
HandleFunc(pattern string, h http.HandlerFunc)
}
Router 用于注册模块接口。pattern 采用 Go 1.22 ServeMux 语法, 但路径部分相对模块前缀,例如 "GET /rules" 实际挂载为 "GET /api/<ID>/rules"。
type Summarizer ¶
type Summarizer interface {
Summary() []SummaryItem
}
Summarizer 由希望在总览页展示状态的模块实现。
type SummaryItem ¶
type SummaryItem struct {
Label string `json:"label"`
Value string `json:"value"`
Level string `json:"level,omitempty"`
}
SummaryItem 是总览页展示的一项指标。Level 为 ok / warn / error / info,用于着色。