2019-12-09 15:02:12 +00:00
|
|
|
package koushin
|
|
|
|
|
|
|
|
import (
|
2019-12-09 16:54:24 +00:00
|
|
|
"html/template"
|
2019-12-09 15:02:12 +00:00
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2019-12-11 14:08:31 +00:00
|
|
|
const pluginDir = "plugins"
|
|
|
|
|
2019-12-11 14:24:39 +00:00
|
|
|
// Plugin extends koushin with additional functionality.
|
2019-12-09 15:02:12 +00:00
|
|
|
type Plugin interface {
|
2019-12-11 14:24:39 +00:00
|
|
|
// Name should return the plugin name.
|
2019-12-09 15:02:12 +00:00
|
|
|
Name() string
|
2019-12-11 14:24:39 +00:00
|
|
|
// LoadTemplate populates t with the plugin's functions and templates.
|
2019-12-11 14:08:31 +00:00
|
|
|
LoadTemplate(t *template.Template) error
|
2019-12-11 14:24:39 +00:00
|
|
|
// SetRoutes populates group with the plugin's routes.
|
2019-12-10 15:00:50 +00:00
|
|
|
SetRoutes(group *echo.Group)
|
2019-12-11 14:24:39 +00:00
|
|
|
// Inject is called prior to rendering a template. It can extend the
|
|
|
|
// template data by setting new items in the Extra map.
|
2019-12-10 15:07:02 +00:00
|
|
|
Inject(name string, data interface{}) error
|
2019-12-11 14:24:39 +00:00
|
|
|
// Close is called when the plugin is unloaded.
|
2019-12-09 15:02:12 +00:00
|
|
|
Close() error
|
|
|
|
}
|
2019-12-16 11:26:26 +00:00
|
|
|
|
|
|
|
var plugins []Plugin
|
|
|
|
|
|
|
|
// RegisterPlugin registers a plugin to be loaded on server startup.
|
|
|
|
func RegisterPlugin(p Plugin) {
|
|
|
|
plugins = append(plugins, p)
|
|
|
|
}
|