Add filter, add READMES
This commit is contained in:
23
backend_go/http_helpers.go
Normal file
23
backend_go/http_helpers.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
enc := json.NewEncoder(w)
|
||||
_ = enc.Encode(v)
|
||||
}
|
||||
|
||||
func writeError(w http.ResponseWriter, status int, msg string) {
|
||||
writeJSON(w, status, ErrorResponse{Detail: msg})
|
||||
}
|
||||
|
||||
func decodeJSON(r io.Reader, dst any) error {
|
||||
dec := json.NewDecoder(r)
|
||||
return dec.Decode(dst)
|
||||
}
|
||||
Reference in New Issue
Block a user