Initial Commit
Some checks failed
ci/woodpecker/tag/manifest unknown status
ci/woodpecker/tag/build/1 Pipeline failed
ci/woodpecker/tag/build/2 Pipeline failed

This commit is contained in:
2025-05-16 16:39:55 +02:00
commit 2b23f0caef
16 changed files with 1157 additions and 0 deletions

30
errors.go Normal file
View File

@@ -0,0 +1,30 @@
package main
import (
"log/slog"
"net/http"
"time"
"go.elara.ws/salix"
)
// handleErr responds with an error page if an error is returned by fn
func handleErr(ns *salix.Namespace, fn func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
err := fn(w, r)
if err != nil {
log.Error("Error in HTTP handler",
slog.String("path", r.URL.Path),
slog.Any("error", err),
)
ns.ExecuteTemplate(w, "error.html", map[string]any{
"errMsg": err.Error(),
})
}
log.Info("Request completed",
slog.String("for", r.RemoteAddr),
slog.Duration("latency", time.Since(start)),
)
})
}