2024-01-22 23:10:14 -05:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.burning.moe/celediel/burning.moe/internal/config"
|
|
|
|
"git.burning.moe/celediel/burning.moe/internal/render"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Handler holds data required for handlers.
|
|
|
|
type Handler struct {
|
|
|
|
Handles string
|
|
|
|
Handler func(w http.ResponseWriter, r *http.Request)
|
|
|
|
}
|
|
|
|
|
|
|
|
var app *config.AppConfig
|
|
|
|
|
|
|
|
// The actual handlers
|
|
|
|
var Handlers = []Handler{
|
|
|
|
// /about
|
|
|
|
{
|
|
|
|
Handles: "/about",
|
2024-01-23 00:55:03 -05:00
|
|
|
Handler: makeBasicHandler("about"),
|
2024-01-22 23:10:14 -05:00
|
|
|
},
|
|
|
|
// / comes last
|
|
|
|
{
|
|
|
|
Handles: "/",
|
2024-01-23 00:55:03 -05:00
|
|
|
Handler: makeBasicHandler("home"),
|
2024-01-22 23:10:14 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise the handlers package.
|
|
|
|
func Initialise(a *config.AppConfig) {
|
|
|
|
app = a
|
|
|
|
}
|
2024-01-23 00:55:03 -05:00
|
|
|
|
2024-01-23 19:10:15 -05:00
|
|
|
// makeBasicHandler returns a simple handler that renders a template from `name`.page.tmpl
|
2024-01-23 00:55:03 -05:00
|
|
|
func makeBasicHandler(name string) func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
app.Logger.Infof("Got request for %s page", name)
|
|
|
|
pageName := name + ".page.tmpl"
|
2024-01-23 19:10:15 -05:00
|
|
|
render.RenderTemplate(w, pageName)
|
2024-01-23 00:55:03 -05:00
|
|
|
}
|
|
|
|
}
|