|
1
|
package api |
|
2
|
|
|
3
|
import ( |
|
4
|
"encoding/json" |
|
5
|
"net/http" |
|
6
|
) |
|
7
|
|
|
8
|
func writeJSON(w http.ResponseWriter, status int, v any) { |
|
9
|
w.Header().Set("Content-Type", "application/json") |
|
10
|
w.WriteHeader(status) |
|
11
|
_ = json.NewEncoder(w).Encode(v) |
|
12
|
} |
|
13
|
|
|
14
|
func writeError(w http.ResponseWriter, status int, msg string) { |
|
15
|
writeJSON(w, status, map[string]string{"error": msg}) |
|
16
|
} |
|
17
|
|