소스 검색

Make render data static

This makes sure fields filled by vanilla koushin keep the right type. A
new Extra field allows plugins to attach their own data.

This also makes it easier to write Go plugins, which would have trouble
working with interface{}.
master
Simon Ser 4 년 전
부모
커밋
9617b412e8
No known key found for this signature in database GPG 키 ID: FDE7BE0E88F5E48
1개의 변경된 파일39개의 추가작업 그리고 14개의 파일을 삭제
  1. +39
    -14
      handlers.go

+ 39
- 14
handlers.go 파일 보기

@@ -16,6 +16,14 @@ import (
"github.com/labstack/echo/v4"
)

type MailboxRenderData struct {
Mailbox *imap.MailboxStatus
Mailboxes []*imap.MailboxInfo
Messages []imapMessage
PrevPage, NextPage int
Extra map[string]interface{}
}

func handleGetMailbox(ectx echo.Context) error {
ctx := ectx.(*context)

@@ -58,12 +66,13 @@ func handleGetMailbox(ectx echo.Context) error {
nextPage = page + 1
}

return ctx.Render(http.StatusOK, "mailbox.html", map[string]interface{}{
"Mailbox": mbox,
"Mailboxes": mailboxes,
"Messages": msgs,
"PrevPage": prevPage,
"NextPage": nextPage,
return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
Mailbox: mbox,
Mailboxes: mailboxes,
Messages: msgs,
PrevPage: prevPage,
NextPage: nextPage,
Extra: make(map[string]interface{}),
})
}

@@ -108,6 +117,15 @@ func handleLogout(ectx echo.Context) error {
return ctx.Redirect(http.StatusFound, "/login")
}

type MessageRenderData struct {
Mailbox *imap.MailboxStatus
Message *imapMessage
Body string
PartPath string
MailboxPage int
Extra map[string]interface{}
}

func handleGetPart(ctx *context, raw bool) error {
mboxName, uid, err := parseMboxAndUid(ctx.Param("mbox"), ctx.Param("uid"))
if err != nil {
@@ -166,15 +184,21 @@ func handleGetPart(ctx *context, raw bool) error {
body = string(b)
}

return ctx.Render(http.StatusOK, "message.html", map[string]interface{}{
"Mailbox": mbox,
"Message": msg,
"Body": body,
"PartPath": partPathString,
"MailboxPage": (mbox.Messages - msg.SeqNum) / messagesPerPage,
return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
Mailbox: mbox,
Message: msg,
Body: body,
PartPath: partPathString,
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
Extra: make(map[string]interface{}),
})
}

type ComposeRenderData struct {
Message *OutgoingMessage
Extra map[string]interface{}
}

func handleCompose(ectx echo.Context) error {
ctx := ectx.(*context)

@@ -269,7 +293,8 @@ func handleCompose(ectx echo.Context) error {
return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
}

return ctx.Render(http.StatusOK, "compose.html", map[string]interface{}{
"Message": &msg,
return ctx.Render(http.StatusOK, "compose.html", &ComposeRenderData{
Message: &msg,
Extra: make(map[string]interface{}),
})
}

불러오는 중...
취소
저장