diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-17 10:58:31 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-17 10:58:31 +0100 |
commit | e78d2db3ea0fbf75a248d0bb2e9bf724e7836272 (patch) | |
tree | 3a7b459c3d55e8e58339cb2eac9477ec93acd608 /plugin_go.go | |
parent | a425e17b0eda3dd7e961127670a46a3b3b2c3d19 (diff) | |
download | alps-e78d2db3ea0fbf75a248d0bb2e9bf724e7836272.tar.gz alps-e78d2db3ea0fbf75a248d0bb2e9bf724e7836272.zip |
Improve docs
Diffstat (limited to 'plugin_go.go')
-rw-r--r-- | plugin_go.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/plugin_go.go b/plugin_go.go index 219e626..cbfe8ee 100644 --- a/plugin_go.go +++ b/plugin_go.go @@ -54,6 +54,13 @@ type goPluginRoute struct { Handler echo.HandlerFunc } +// GoPlugin is a helper to create Go plugins. +// +// Use this struct to define your plugin, then call RegisterPlugin: +// +// p := GoPlugin{Name: "my-plugin"} +// // Define routes, template functions, etc +// koushin.RegisterPlugin(p.Plugin()) type GoPlugin struct { Name string @@ -62,6 +69,10 @@ type GoPlugin struct { templateFuncs template.FuncMap } +// AddRoute registers a new HTTP route. +// +// The echo.Context passed to the HTTP handler can be type-asserted to +// *koushin.Context. func (p *GoPlugin) AddRoute(method, path string, handler echo.HandlerFunc) { p.routes = append(p.routes, goPluginRoute{method, path, handler}) } @@ -82,6 +93,7 @@ func (p *GoPlugin) PUT(path string, handler echo.HandlerFunc) { p.AddRoute(http.MethodPut, path, handler) } +// TemplateFuncs registers new template functions. func (p *GoPlugin) TemplateFuncs(funcs template.FuncMap) { if p.templateFuncs == nil { p.templateFuncs = make(template.FuncMap, len(funcs)) @@ -92,6 +104,7 @@ func (p *GoPlugin) TemplateFuncs(funcs template.FuncMap) { } } +// Plugin returns an object implementing Plugin. func (p *GoPlugin) Plugin() Plugin { return &goPlugin{p} } |