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:
parent
cc39aa7f08
commit
273da5b4db
|
|
@ -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{}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue