feat(plugins): add example plugin

Demonstrates all plugin capabilities: authenticated and unauthenticated
routes, event listeners, and lifecycle hooks. Uses a shared singleton
for factory functions so Init() state is available to route handlers.
This commit is contained in:
kolaente 2026-03-30 22:22:02 +02:00 committed by kolaente
parent cc39aa7f08
commit 273da5b4db
1 changed files with 13 additions and 1 deletions

View File

@ -92,7 +92,19 @@ func handleStatus(c *echo.Context) error {
}) })
} }
func NewPlugin() plugins.Plugin { return &ExamplePlugin{} } // singleton ensures all factory functions return the same instance so that state
// initialized in Init() (e.g. event listeners, DB connections) is available to
// route handlers and other capabilities.
var singleton = &ExamplePlugin{}
func NewPlugin() plugins.Plugin { return singleton }
// Typed factory functions for Yaegi compatibility.
// Yaegi wraps return values per the declared return type, so sub-interface type
// assertions (Plugin -> AuthenticatedRouterPlugin) don't work. These typed
// factories ensure Yaegi wraps the value with the correct interface wrapper.
func NewAuthenticatedRouterPlugin() plugins.AuthenticatedRouterPlugin { return singleton }
func NewUnauthenticatedRouterPlugin() plugins.UnauthenticatedRouterPlugin { return singleton }
type TestListener struct{} type TestListener struct{}