Some checks failed
CI / Build & Test (push) Failing after 40s
- kernel/plugin: 定义 Plugin 接口(Metadata/FxOption/SetupRoutes/Init) - kernel/plugin: 全局 Registry(Register/All/InitAll/Reset) - modules/example: 完整 4 层示例插件,实现 Plugin 接口 - config: 新增 PluginConfig(enabled 列表) - app.go: 集成插件系统 — fx.Invoke 注册 + plugin.All() 路由 + InitAll 生命周期
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
// Package plugin defines the contract for MengStack plugins.
|
|
//
|
|
// A plugin is a self-contained extension that follows the same 4-layer
|
|
// architecture as built-in modules. Each plugin provides:
|
|
//
|
|
// - FxOption: dependency injection wiring (repositories, services, handlers)
|
|
// - SetupRoutes: HTTP route registration on the Gin engine
|
|
// - Init: optional startup hook for background workers, caches, etc.
|
|
//
|
|
// To create a plugin:
|
|
// 1. Create a package under internal/modules/<name>/
|
|
// 2. Follow the 4-layer pattern: domain → infrastructure → application → interfaces
|
|
// 3. Implement the Plugin interface
|
|
// 4. Register in internal/app/app.go's plugin list
|
|
package plugin
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// Metadata describes a plugin's identity.
|
|
type Metadata struct {
|
|
Name string
|
|
Version string
|
|
Description string
|
|
}
|
|
|
|
// Plugin is the contract every MengStack plugin must implement.
|
|
type Plugin interface {
|
|
// Metadata returns the plugin's identity.
|
|
Metadata() Metadata
|
|
|
|
// FxOption returns the fx.Module for dependency injection.
|
|
FxOption() fx.Option
|
|
|
|
// SetupRoutes registers HTTP routes on the Gin engine.
|
|
// authMW is the JWT authentication middleware.
|
|
SetupRoutes(engine *gin.Engine, authMW gin.HandlerFunc)
|
|
|
|
// Init is called after all dependencies are resolved and before
|
|
// the HTTP server starts. Use it for background workers, warm-up
|
|
// caches, or external service connections.
|
|
// Returning nil indicates success.
|
|
Init() error
|
|
}
|