aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-17 10:58:31 +0100
committerSimon Ser <contact@emersion.fr>2019-12-17 10:58:31 +0100
commite78d2db3ea0fbf75a248d0bb2e9bf724e7836272 (patch)
tree3a7b459c3d55e8e58339cb2eac9477ec93acd608
parenta425e17b0eda3dd7e961127670a46a3b3b2c3d19 (diff)
downloadalps-e78d2db3ea0fbf75a248d0bb2e9bf724e7836272.tar.gz
alps-e78d2db3ea0fbf75a248d0bb2e9bf724e7836272.zip
Improve docs
-rw-r--r--README.md26
-rw-r--r--plugin_go.go13
-rw-r--r--plugins/base/handlers.go2
3 files changed, 33 insertions, 8 deletions
diff --git a/README.md b/README.md
index 458b5a9..e5fb1d5 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,20 @@ Assets in `themes/<name>/assets/*` are served by the HTTP server at
## Plugins
-Lua plugins are supported. They can be dropped in `plugins/<name>/main.lua`.
+Plugins can be written in Go or in Lua and live in `plugins/<name>/`.
+
+Plugins can provide their own templates in `plugins/<name>/public/*.html`.
+Assets in `plugins/<name>/public/assets/*` are served by the HTTP server at
+`/plugins/<name>/assets/*`.
+
+### Go plugins
+
+They can use the [Go plugin helpers] and need to be included at compile-time in
+`cmd/koushin/main.go`.
+
+### Lua plugins
+
+The entry point is at `plugins/<name>/main.lua`.
API:
@@ -28,15 +41,14 @@ API:
* `koushin.set_route(method, path, f)`: register a new HTTP route, `f` will be
called with the HTTP context
-Plugins can provide their own templates in `plugins/<name>/public/*.html`.
-Assets in `plugins/<name>/public/assets/*` are served by the HTTP server at
-`/plugins/<name>/assets/*`.
-
## Contributing
-Send patches [on the mailing list](https://lists.sr.ht/~sircmpwn/koushin),
-report bugs [on the issue tracker](https://todo.sr.ht/~sircmpwn/koushin).
+Send patches on the [mailing list], report bugs on the [issue tracker].
## License
MIT
+
+[Go plugin helpers]: https://godoc.org/git.sr.ht/~emersion/koushin#GoPlugin
+[mailing list]: https://lists.sr.ht/~sircmpwn/koushin
+[issue tracker]: https://todo.sr.ht/~sircmpwn/koushin
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}
}
diff --git a/plugins/base/handlers.go b/plugins/base/handlers.go
index c36cfa7..923ab4f 100644
--- a/plugins/base/handlers.go
+++ b/plugins/base/handlers.go
@@ -11,8 +11,8 @@ import (
"git.sr.ht/~emersion/koushin"
"github.com/emersion/go-imap"
- imapclient "github.com/emersion/go-imap/client"
imapmove "github.com/emersion/go-imap-move"
+ imapclient "github.com/emersion/go-imap/client"
"github.com/emersion/go-message"
"github.com/emersion/go-smtp"
"github.com/labstack/echo/v4"