refactor api package comments

* use encoding/json for comment parsing

* refactor by moving loop code to an UnmarshalJSON

* use a preallocated array and indices to maintain order while using
  goroutines again, this was removed a while ago

* use new struct in comment.hbs and contextComment.hbs

* rewriteUrl partial to reduce rimgo-specific code in api

* move RenderError into pages package to avoid import cycle between render and utils
This commit is contained in:
orangix
2026-01-25 05:08:10 +01:00
parent c208a55f40
commit 02be603dcc
15 changed files with 234 additions and 137 deletions

View File

@@ -23,13 +23,13 @@ func wrapHandler(h handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if v := recover(); v != nil {
utils.RenderError(w, r, 500, fmt.Sprint(v))
pages.RenderError(w, r, 500, fmt.Sprint(v))
}
}()
err := h(w, r)
if err != nil {
fmt.Println(err)
utils.RenderError(w, r, 500, err.Error())
pages.RenderError(w, r, 500, err.Error())
}
})
}
@@ -61,14 +61,14 @@ func main() {
if os.Getenv("ENV") == "dev" {
app.Handle("GET /errors/429", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
utils.RenderError(w, r, 429)
pages.RenderError(w, r, 429)
}))
app.Handle("GET /errors/429/img", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Location", "/static/img/error-429.png")
w.WriteHeader(302)
}))
app.Handle("GET /errors/404", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
utils.RenderError(w, r, 404)
pages.RenderError(w, r, 404)
}))
app.Handle("GET /errors/404/img", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Location", "/static/img/error-404.png")