Some checks failed
CI / Build & Test (push) Failing after 1m31s
- Add user management endpoints (list/create/get/update/delete) with pagination and search - Add dashboard stats endpoint with tenant/user/online counts and growth metrics - Add tenant resolver middleware for multi-tenant request scoping - Add i18n kernel with zh/en message files and AcceptLanguage middleware - Add WebSocket hub/handler for real-time communication - Add job scheduler kernel with cron support - Add plugin sandbox for isolated execution - Add storage kernel (local filesystem) - Add event bus kernel for pub/sub - Add cache kernel abstraction - Add database migration runner and version upgrade checker - Add rate limiting middleware with Redis backend - Add SQL migrations for rbac, audit_logs, settings, notifications, examples - Extend user repository with list/delete/count operations - Register all module routes with tenant resolver
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package interfaces
|
|
|
|
import (
|
|
"io/fs"
|
|
|
|
"mengstack/internal/app/middleware"
|
|
"mengstack/internal/kernel/plugin"
|
|
"mengstack/internal/kernel/tenant"
|
|
"mengstack/internal/modules/example/application"
|
|
"mengstack/internal/modules/example/infrastructure"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// ExamplePlugin implements plugin.Plugin.
|
|
type ExamplePlugin struct {
|
|
handler *Handler
|
|
}
|
|
|
|
// New creates the example plugin and registers it in the global plugin registry.
|
|
func New(handler *Handler) *ExamplePlugin {
|
|
p := &ExamplePlugin{handler: handler}
|
|
plugin.Register(p)
|
|
return p
|
|
}
|
|
|
|
func (p *ExamplePlugin) Metadata() plugin.Metadata {
|
|
return plugin.Metadata{
|
|
Name: "example",
|
|
Version: "0.1.0",
|
|
Description: "示例插件 — 演示插件开发模式",
|
|
}
|
|
}
|
|
|
|
func (p *ExamplePlugin) Permissions() plugin.Permissions {
|
|
return plugin.Permissions{
|
|
Database: []string{""}, // full database access (all tables)
|
|
Storage: false, // no file storage
|
|
Network: []string{}, // no network access
|
|
Events: []string{"*"}, // can emit any event
|
|
Routes: []string{"/api/v1/examples", "/api/v1/examples/*"},
|
|
AdminPanel: false,
|
|
}
|
|
}
|
|
|
|
func (p *ExamplePlugin) FxOption() fx.Option {
|
|
return fx.Module("example-plugin",
|
|
fx.Provide(
|
|
infrastructure.NewRepository,
|
|
application.NewService,
|
|
NewHandler,
|
|
),
|
|
)
|
|
}
|
|
|
|
func (p *ExamplePlugin) SetupRoutes(engine *gin.Engine, authMW gin.HandlerFunc, tenantResolver tenant.Resolver) {
|
|
g := engine.Group("/api/v1/examples", authMW, middleware.MultiTenant(tenantResolver))
|
|
g.POST("", p.handler.Create)
|
|
g.GET("", p.handler.List)
|
|
g.GET("/:id", p.handler.Get)
|
|
g.DELETE("/:id", p.handler.Delete)
|
|
}
|
|
|
|
func (p *ExamplePlugin) MigrationsFS() fs.FS {
|
|
return nil
|
|
}
|
|
|
|
func (p *ExamplePlugin) Init() error {
|
|
return nil
|
|
}
|
|
|
|
// Module is the fx module for the example plugin.
|
|
// It provides all dependencies and the ExamplePlugin itself.
|
|
var Module = fx.Module("example-plugin",
|
|
fx.Provide(
|
|
infrastructure.NewRepository,
|
|
application.NewService,
|
|
NewHandler,
|
|
New,
|
|
),
|
|
)
|