addded services

This commit is contained in:
2026-07-15 13:29:08 +03:00
parent ec33cd5398
commit 9ebbb83bdb
105 changed files with 10833 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
package httpx
import (
"encoding/json"
"net/http"
)
func WriteJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(v)
}
func Error(w http.ResponseWriter, status int, msg string) {
WriteJSON(w, status, map[string]any{"ok": false, "error": msg})
}
func ReadJSON(r *http.Request, v any) error {
dec := json.NewDecoder(r.Body)
return dec.Decode(v)
}