Skip to content

Commit

Permalink
refactor: remove error template
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNotGoodName committed Jul 20, 2022
1 parent ce9b11a commit 2c52ec4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
6 changes: 3 additions & 3 deletions left/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Controller) IndexGet(w http.ResponseWriter, r *http.Request) {
page := paginate.NewPage(pageQ, limitQ, ascendingQ)
envs, err := c.envelopeService.ListEnvelope(r.Context(), &page)
if err != nil {
view.RenderError(w, http.StatusInternalServerError, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

Expand All @@ -48,7 +48,7 @@ func (c *Controller) EnvelopeGet(w http.ResponseWriter, r *http.Request) {
if errors.Is(err, core.ErrMessageNotFound) {
code = http.StatusNotFound
}
view.RenderError(w, code, err)
http.Error(w, err.Error(), code)
return
}

Expand All @@ -64,7 +64,7 @@ func (c *Controller) EnvelopeHTMLGet(w http.ResponseWriter, r *http.Request) {
if errors.Is(err, core.ErrMessageNotFound) {
code = http.StatusNotFound
}
view.RenderError(w, code, err)
http.Error(w, err.Error(), code)
return
}

Expand Down
7 changes: 6 additions & 1 deletion left/view/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ package view
import (
"html/template"
"io/fs"
"net/http"

"github.com/ItsNotGoodName/smtpbridge/core/envelope"
"github.com/ItsNotGoodName/smtpbridge/core/paginate"
)

func Render(rw http.ResponseWriter, code int, page string, data interface{}) {
rw.WriteHeader(code)
getTemplate(page).Execute(rw, data)
}

func parseTemplate(name string, templateFS fs.FS) *template.Template {
return template.Must(template.New(name).Funcs(helperMap).ParseFS(templateFS, name, "**/*.html"))
}

const (
ErrorPage string = "error.html"
IndexPage string = "index.html"
EnvelopePage string = "envelope.html"
)
Expand Down
11 changes: 0 additions & 11 deletions left/view/template/error.html

This file was deleted.

18 changes: 0 additions & 18 deletions left/view/view.go

This file was deleted.

0 comments on commit 2c52ec4

Please sign in to comment.