Выполнение lab4 на 4

This commit is contained in:
Daria0w0
2026-11-06 17:35:48 +03:00
parent 9197e151ba
commit 879463c947
89 changed files with 5551 additions and 108 deletions
+6 -2
View File
@@ -19,6 +19,10 @@ func readJSON(
dst any,
requiredFields ...string,
) bool {
return readJSONFields(w, r, dst, requiredFields, nil)
}
func readJSONFields(w http.ResponseWriter, r *http.Request, dst any, requiredFields, optionalFields []string) bool {
mediaType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil || mediaType != "application/json" {
writeError(
@@ -67,8 +71,8 @@ func readJSON(
return invalid()
}
for name := range fields {
if !slices.Contains(requiredFields, name) {
for name, value := range fields {
if (!slices.Contains(requiredFields, name) && !slices.Contains(optionalFields, name)) || bytes.Equal(bytes.TrimSpace(value), []byte("null")) {
return invalid()
}
}