diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-17 11:36:08 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-17 11:36:08 +0100 |
commit | 3aea768cad3a5c9bb2a16039beee4b3dc8ee9d48 (patch) | |
tree | 0cf5866e9027eedf30de1e22af6ddc3d4427565c | |
parent | b8407569f0a3807ab6bee31c6b0c5f07455f7cb9 (diff) | |
download | alps-3aea768cad3a5c9bb2a16039beee4b3dc8ee9d48.tar.gz alps-3aea768cad3a5c9bb2a16039beee4b3dc8ee9d48.zip |
plugins/base: extract route registration into function
-rw-r--r-- | plugins/base/plugin.go | 29 | ||||
-rw-r--r-- | plugins/base/routes.go (renamed from plugins/base/handlers.go) | 29 |
2 files changed, 30 insertions, 28 deletions
diff --git a/plugins/base/plugin.go b/plugins/base/plugin.go index 3673885..5a946f5 100644 --- a/plugins/base/plugin.go +++ b/plugins/base/plugin.go @@ -2,7 +2,6 @@ package koushinbase import ( "git.sr.ht/~emersion/koushin" - "github.com/labstack/echo/v4" ) const messagesPerPage = 50 @@ -11,33 +10,7 @@ func init() { p := koushin.GoPlugin{Name: "base"} p.TemplateFuncs(templateFuncs) - - p.GET("/mailbox/:mbox", handleGetMailbox) - p.POST("/mailbox/:mbox", handleGetMailbox) - - p.GET("/message/:mbox/:uid", func(ectx echo.Context) error { - ctx := ectx.(*koushin.Context) - return handleGetPart(ctx, false) - }) - p.GET("/message/:mbox/:uid/raw", func(ectx echo.Context) error { - ctx := ectx.(*koushin.Context) - return handleGetPart(ctx, true) - }) - - p.GET("/login", handleLogin) - p.POST("/login", handleLogin) - - p.GET("/logout", handleLogout) - - p.GET("/compose", handleCompose) - p.POST("/compose", handleCompose) - - p.GET("/message/:mbox/:uid/reply", handleCompose) - p.POST("/message/:mbox/:uid/reply", handleCompose) - - p.POST("/message/:mbox/:uid/move", handleMove) - - p.POST("/message/:mbox/:uid/delete", handleDelete) + registerRoutes(&p) koushin.RegisterPlugin(p.Plugin()) } diff --git a/plugins/base/handlers.go b/plugins/base/routes.go index 923ab4f..c0f5817 100644 --- a/plugins/base/handlers.go +++ b/plugins/base/routes.go @@ -379,3 +379,32 @@ func handleDelete(ectx echo.Context) error { return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", mboxName)) } + +func registerRoutes(p *koushin.GoPlugin) { + p.GET("/mailbox/:mbox", handleGetMailbox) + p.POST("/mailbox/:mbox", handleGetMailbox) + + p.GET("/message/:mbox/:uid", func(ectx echo.Context) error { + ctx := ectx.(*koushin.Context) + return handleGetPart(ctx, false) + }) + p.GET("/message/:mbox/:uid/raw", func(ectx echo.Context) error { + ctx := ectx.(*koushin.Context) + return handleGetPart(ctx, true) + }) + + p.GET("/login", handleLogin) + p.POST("/login", handleLogin) + + p.GET("/logout", handleLogout) + + p.GET("/compose", handleCompose) + p.POST("/compose", handleCompose) + + p.GET("/message/:mbox/:uid/reply", handleCompose) + p.POST("/message/:mbox/:uid/reply", handleCompose) + + p.POST("/message/:mbox/:uid/move", handleMove) + + p.POST("/message/:mbox/:uid/delete", handleDelete) +} |