module

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package module 定义功能模块的统一接口。

每个模块拥有独立的配置文件(config.Store 中以 ID 命名)、独立的日志缓冲, 以及挂载在 /api/<ID>/ 下的管理接口。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env struct {
	Store *config.Store
	Logs  *logbuf.Buffer
}

Env 是框架注入给模块的运行环境。

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,用于着色。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL