alps/plugin.go

37 lines
1.1 KiB
Go
Raw Normal View History

2020-05-13 12:07:44 +00:00
package alps
2019-12-09 15:02:12 +00:00
import (
2019-12-09 16:54:24 +00:00
"html/template"
2019-12-09 15:02:12 +00:00
"github.com/labstack/echo/v4"
)
// PluginDir is the path to the plugins directory.
const PluginDir = "plugins"
2020-05-13 12:07:44 +00:00
// Plugin extends alps 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.
LoadTemplate(t *template.Template) error
2019-12-11 14:24:39 +00:00
// SetRoutes populates group with the plugin's routes.
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.
Inject(ctx *Context, name string, data RenderData) 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
}
// PluginLoaderFunc loads plugins for the provided server.
type PluginLoaderFunc func(*Server) ([]Plugin, error)
var pluginLoaders []PluginLoaderFunc
// RegisterPluginLoader registers a plugin loader. The loader will be called on
// server start-up and reload.
func RegisterPluginLoader(f PluginLoaderFunc) {
pluginLoaders = append(pluginLoaders, f)
}