This commit is contained in:
Max Richter
2025-09-24 21:32:27 +02:00
parent 26c303d9cf
commit 66ab9ca7fc
21 changed files with 450 additions and 9 deletions

View File

@@ -0,0 +1,20 @@
package handler
import (
"encoding/json"
"net/http"
)
type ErrorResponse struct {
Error string `json:"error"`
}
func writeError(w http.ResponseWriter, code int, err error) {
writeJSON(w, code, ErrorResponse{Error: err.Error()})
}
func writeJSON(w http.ResponseWriter, code int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
_ = json.NewEncoder(w).Encode(v)
}