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, ), )