initial rebuild

This commit is contained in:
allanice001
2025-09-01 13:34:13 +01:00
commit 95bd9615d1
100 changed files with 12440 additions and 0 deletions

39
internal/response/json.go Normal file
View File

@@ -0,0 +1,39 @@
package response
import (
"encoding/json"
"net/http"
)
func JSON(w http.ResponseWriter, status int, data any) error {
return JSONWithHeaders(w, status, data, nil)
}
func JSONWithHeaders(w http.ResponseWriter, status int, data any, headers http.Header) error {
js, err := json.MarshalIndent(data, "", "\t")
if err != nil {
return err
}
js = append(js, '\n')
for key, value := range headers {
w.Header()[key] = value
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
w.Write(js)
return nil
}
func Error(w http.ResponseWriter, status int, msg string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(map[string]string{"error": msg})
}
func NoContent(w http.ResponseWriter) {
w.WriteHeader(http.StatusNoContent)
}