Documentation
¶
Overview ¶
Package api 提供 Remilia 框架的 RESTful 管理 API。
架构概述:
api.Server 封装了 HTTP 服务器和路由注册,对外暴露一组 /api/v1/* 端点。
所有端点(除 /health 和 /version)均通过 Bearer Token 认证。
统一响应格式为 { code, message, data }。
端点分类:
- Bot 管理:/api/v1/bots/*(列表、详情、启停)
- 插件管理:/api/v1/plugins/*(列表、详情、启用/禁用/重载)
- 配置:/api/v1/config(当前配置快照,只读)
- 系统:/api/v1/health, /version, /stats
使用方式:
deps := api.Deps{Bot: bot, PluginMgr: pm, Registry: reg}
srv := api.NewServer(":9002", "api-key", deps)
srv.Start()
defer srv.Stop(ctx)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendLogEntry ¶
func AppendLogEntry(level, msg string)
AppendLogEntry 直接向全局日志缓冲区追加条目(由 main 的 zerolog hook 调用)。
func GetBuildInfo ¶ added in v1.28.0
func GetBuildInfo() (commit, date string)
GetBuildInfo 返回 main 包注入的构建信息(Git commit 与构建时间)。 未经 SetBuildInfo 注入时两个返回值均为空字符串。
func SetBuildInfo ¶
func SetBuildInfo(commit, date string)
SetBuildInfo 由 main 包在初始化时注入构建信息。 commit 和 date 是 -ldflags 传入的编译时变量。
Types ¶
type APIResponse ¶
type APIResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
APIResponse 是统一 API 响应结构。 所有端点均返回此格式:
成功:{ "code": 0, "message": "ok", "data": {...} }
失败:{ "code": 404, "message": "...", "data": null }
type BotInfo ¶
type BotInfo struct {
Name string `json:"name"`
Status string `json:"status"` // "running" | "stopped"
Uptime string `json:"uptime"` // 人类可读的运行时长
Version string `json:"version"` // 框架版本
Platforms []string `json:"platforms,omitempty"` // 已接入的聊天平台列表
PluginCount int `json:"plugin_count"` // 已注册插件数量
}
BotInfo 是 Bot 实例的公开摘要信息,用于列表和详情响应。
type Deps ¶
type Deps struct {
Bot *remilia.Bot
PluginMgr *plugin.Manager
Registry *platform.Registry
Engine *engine.Engine
FSMMgr *fsm.Manager
PermissionMgr *permission.Manager
ConfigPath string
DashboardHandler http.Handler
}
Deps 是 Server 的依赖注入容器。
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
LogBuffer 环形日志缓冲区
func NewLogBuffer ¶
type LogCaptureWriter ¶
type LogCaptureWriter struct {
// contains filtered or unexported fields
}
LogCaptureWriter 实现 io.Writer,解析 zerolog JSON 输出并存入环形缓冲区。
func NewLogCaptureWriter ¶
func NewLogCaptureWriter() *LogCaptureWriter
NewLogCaptureWriter 创建一个日志捕获 writer。 使用前调用 logger.SetExtraWriter(w),然后 logger.Init()。
type LogEntry ¶
type LogEntry struct {
Time string `json:"time"`
Level string `json:"level"`
Message string `json:"message"`
}
LogEntry 日志条目
type PluginInfo ¶
type PluginInfo struct {
Name string `json:"name"`
State string `json:"state"` // Loaded | Disabled | Error 等
Version string `json:"version"` // 插件版本
Uptime string `json:"uptime"` // 运行时长
Dependencies []string `json:"dependencies,omitempty"` // 依赖的其他插件
MatcherCount int `json:"matcher_count"` // 注册的匹配器数量
LastError string `json:"last_error,omitempty"` // 最后错误信息
LoadTime string `json:"load_time,omitempty"` // RFC3339 格式的加载时间
}
PluginInfo 是插件的公开摘要信息,用于列表响应。 详情响应直接使用 plugin.Status,此处仅用于列表场景的轻量结构。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.