Выполнение lab4 на 4
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user