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
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var (
|
|
registry []Plugin
|
|
mu sync.RWMutex
|
|
)
|
|
|
|
// Register adds a plugin to the global registry.
|
|
// Typically called in init() or during application bootstrap.
|
|
func Register(p Plugin) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
registry = append(registry, p)
|
|
}
|
|
|
|
// All returns a copy of all registered plugins.
|
|
func All() []Plugin {
|
|
mu.RLock()
|
|
defer mu.RUnlock()
|
|
out := make([]Plugin, len(registry))
|
|
copy(out, registry)
|
|
return out
|
|
}
|
|
|
|
// InitAll initializes all registered plugins in order.
|
|
// Each plugin's permissions are registered in the sandbox, and Init() is
|
|
// wrapped with panic recovery so one plugin's failure doesn't crash the process.
|
|
func InitAll(log *zap.Logger, sandbox *Sandbox) error {
|
|
for _, p := range All() {
|
|
meta := p.Metadata()
|
|
perms := p.Permissions()
|
|
|
|
sandbox.Register(meta.Name, perms)
|
|
|
|
log.Info("initializing plugin",
|
|
zap.String("name", meta.Name),
|
|
zap.String("version", meta.Version),
|
|
)
|
|
if err := sandbox.SafeInit(p); err != nil {
|
|
return fmt.Errorf("plugin %s init failed: %w", meta.Name, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Reset clears the registry. Used in tests only.
|
|
func Reset() {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
registry = nil
|
|
}
|