use less single letter variables

This commit is contained in:
Lilian Jónsdóttir 2024-01-27 16:26:46 -08:00
parent d771ddb3d3
commit 95fac5c405
2 changed files with 12 additions and 12 deletions

View file

@ -13,9 +13,9 @@ var Middleware []func(next http.Handler) http.Handler = []func(next http.Handler
middleware.RealIP,
// plus custom request logger
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
app.Logger.Info("REQUEST", "url", r.URL, "ip", r.RemoteAddr, "useragent", r.UserAgent())
next.ServeHTTP(w, r)
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
app.Logger.Info("REQUEST", "url", request.URL, "ip", request.RemoteAddr, "useragent", request.UserAgent())
next.ServeHTTP(writer, request)
})
},
middleware.Recoverer,

View file

@ -16,7 +16,7 @@ import (
// Handler holds data required for handlers.
type Handler struct {
Handles string
Handler func(w http.ResponseWriter, r *http.Request)
Handler func(writer http.ResponseWriter, request *http.Request)
}
var app *config.AppConfig
@ -43,7 +43,7 @@ func Initialise(a *config.AppConfig) {
}
// HomeHandler handles /, generating data from Handlers
func HomeHandler(w http.ResponseWriter, r *http.Request) {
func HomeHandler(writer http.ResponseWriter, request *http.Request) {
page := "home.page.tmpl"
d := models.TemplateData{}
@ -72,20 +72,20 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
d.LinkMap = make(map[string][]models.Link)
d.LinkMap["Pages"] = pages
app.Logger.Debug("handling home with some data", "data", &d)
render.RenderTemplateWithData(w, "home.page.tmpl", &d)
render.RenderTemplateWithData(writer, "home.page.tmpl", &d)
}
// makeBasicHandler returns a simple handler that renders a template from `name`.page.tmpl
func makeBasicHandler(name string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
func makeBasicHandler(name string) func(writer http.ResponseWriter, request *http.Request) {
return func(writer http.ResponseWriter, request *http.Request) {
pageName := name + ".page.tmpl"
render.RenderTemplate(w, pageName)
render.RenderTemplate(writer, pageName)
}
}
// makeLinksHandler returns a handler for links.tmpl with template data from `name`
func makeLinksHandler(name string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
func makeLinksHandler(name string) func(writer http.ResponseWriter, request *http.Request) {
return func(writer http.ResponseWriter, request *http.Request) {
page := "links.tmpl"
template, err := render.GetTemplateFromCache(page)
if err != nil {
@ -100,6 +100,6 @@ func makeLinksHandler(name string) func(w http.ResponseWriter, r *http.Request)
}
app.Logger.Debug("handling a links page", "data", &data)
render.RenderTemplateWithData(w, page, &data)
render.RenderTemplateWithData(writer, page, &data)
}
}