first commit
This commit is contained in:
19
internal/http/handlers/respond.go
Normal file
19
internal/http/handlers/respond.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, code int, body any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
if body == nil {
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(body)
|
||||
}
|
||||
|
||||
func WriteError(w http.ResponseWriter, code int, kind, detail string) {
|
||||
WriteJSON(w, code, map[string]string{"error": kind, "detail": detail})
|
||||
}
|
||||
Reference in New Issue
Block a user