mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 17:41:13 +00:00
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:
8
main.go
8
main.go
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user