Improve docs
This commit is contained in:
parent
a425e17b0e
commit
e78d2db3ea
3 changed files with 33 additions and 8 deletions
26
README.md
26
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
|
||||
|
|
13
plugin_go.go
13
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}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue