aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-17 15:19:37 +0100
committerSimon Ser <contact@emersion.fr>2019-12-17 15:19:37 +0100
commitf106c1125f3d0e0f9772d2c5f595fc52ec7dda5b (patch)
treeff76c2fa8dd3d9f1c6f17682b07abf419f33a2f0 /plugins/base
parent020e27fe459b0ed66a48b46cb2878520ed4a517b (diff)
downloadalps-f106c1125f3d0e0f9772d2c5f595fc52ec7dda5b.tar.gz
alps-f106c1125f3d0e0f9772d2c5f595fc52ec7dda5b.zip
Make Go plugin handlers take a *Context
Take a *Context instead of a echo.Context. This saves a type assertion in each handler.
Diffstat (limited to 'plugins/base')
-rw-r--r--plugins/base/routes.go38
1 files changed, 11 insertions, 27 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index f3f196a..35e72de 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -19,19 +19,17 @@ import (
)
func registerRoutes(p *koushin.GoPlugin) {
- p.GET("/", func(ectx echo.Context) error {
- return ectx.Redirect(http.StatusFound, "/mailbox/INBOX")
+ p.GET("/", func(ctx *koushin.Context) error {
+ return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
})
p.GET("/mailbox/:mbox", handleGetMailbox)
p.POST("/mailbox/:mbox", handleGetMailbox)
- p.GET("/message/:mbox/:uid", func(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
+ p.GET("/message/:mbox/:uid", func(ctx *koushin.Context) error {
return handleGetPart(ctx, false)
})
- p.GET("/message/:mbox/:uid/raw", func(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
+ p.GET("/message/:mbox/:uid/raw", func(ctx *koushin.Context) error {
return handleGetPart(ctx, true)
})
@@ -62,9 +60,7 @@ type MailboxRenderData struct {
Query string
}
-func handleGetMailbox(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleGetMailbox(ctx *koushin.Context) error {
mboxName, err := url.PathUnescape(ctx.Param("mbox"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -125,9 +121,7 @@ func handleGetMailbox(ectx echo.Context) error {
})
}
-func handleLogin(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleLogin(ctx *koushin.Context) error {
username := ctx.FormValue("username")
password := ctx.FormValue("password")
if username != "" && password != "" {
@@ -146,9 +140,7 @@ func handleLogin(ectx echo.Context) error {
return ctx.Render(http.StatusOK, "login.html", koushin.NewBaseRenderData(ctx))
}
-func handleLogout(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleLogout(ctx *koushin.Context) error {
ctx.Session.Close()
ctx.SetSession(nil)
return ctx.Redirect(http.StatusFound, "/login")
@@ -255,9 +247,7 @@ type ComposeRenderData struct {
Message *OutgoingMessage
}
-func handleCompose(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleCompose(ctx *koushin.Context) error {
var msg OutgoingMessage
if strings.ContainsRune(ctx.Session.Username(), '@') {
msg.From = ctx.Session.Username()
@@ -358,9 +348,7 @@ func handleCompose(ectx echo.Context) error {
})
}
-func handleMove(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleMove(ctx *koushin.Context) error {
mboxName, uid, err := parseMboxAndUid(ctx.Param("mbox"), ctx.Param("uid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -391,9 +379,7 @@ func handleMove(ectx echo.Context) error {
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(to)))
}
-func handleDelete(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleDelete(ctx *koushin.Context) error {
mboxName, uid, err := parseMboxAndUid(ctx.Param("mbox"), ctx.Param("uid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -432,9 +418,7 @@ func handleDelete(ectx echo.Context) error {
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(mboxName)))
}
-func handleSetFlags(ectx echo.Context) error {
- ctx := ectx.(*koushin.Context)
-
+func handleSetFlags(ctx *koushin.Context) error {
mboxName, uid, err := parseMboxAndUid(ctx.Param("mbox"), ctx.Param("uid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)