aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/web/handlers')
-rw-r--r--cmd/web/handlers/blog.go12
-rw-r--r--cmd/web/handlers/routes.go10
2 files changed, 16 insertions, 6 deletions
diff --git a/cmd/web/handlers/blog.go b/cmd/web/handlers/blog.go
index 5a874f4..da3aec2 100644
--- a/cmd/web/handlers/blog.go
+++ b/cmd/web/handlers/blog.go
@@ -6,7 +6,13 @@ import (
"net/http"
)
-func (ctx *HandlerContext) blogIndex(w http.ResponseWriter, r *http.Request) {
+type blogContext struct {
+ err *log.Logger
+
+ Name string
+}
+
+func (ctx blogContext) index(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
@@ -19,14 +25,14 @@ func (ctx *HandlerContext) blogIndex(w http.ResponseWriter, r *http.Request) {
compiled, err := template.ParseFiles(files...)
if err != nil {
- log.Println(err.Error())
+ ctx.err.Print(err.Error())
http.Error(w, "Internal Server Error", 500)
return
}
err = compiled.ExecuteTemplate(w, "base", ctx)
if err != nil {
- log.Println(err.Error())
+ ctx.err.Print(err.Error())
http.Error(w, "Internal Server Error", 500)
}
}
diff --git a/cmd/web/handlers/routes.go b/cmd/web/handlers/routes.go
index 5a57440..5c927c4 100644
--- a/cmd/web/handlers/routes.go
+++ b/cmd/web/handlers/routes.go
@@ -2,13 +2,17 @@ package handlers
import (
"github.com/gorilla/mux"
+ "paterissa.net/mblog/cmd/web/types"
)
-func RegisterEndpoints(webmaster string) *mux.Router {
- ctx := HandlerContext{webmaster}
+func RegisterEndpoints(app types.Application) *mux.Router {
+ ctx := blogContext{
+ err: app.Err,
+ Name: app.Env.Webmaster,
+ }
blogRouter := mux.NewRouter()
- blogRouter.HandleFunc("/", ctx.blogIndex)
+ blogRouter.HandleFunc("/", ctx.index)
return blogRouter
}