From 60c9cc6946d6d76ca1043f31734e08aca8fae198 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 11 Feb 2020 11:55:08 +0100 Subject: [PATCH] Use non-anonymous struct to decode devices list --- clientapi/routing/device.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clientapi/routing/device.go b/clientapi/routing/device.go index 783e5e7fa..eb7cd0b0c 100644 --- a/clientapi/routing/device.go +++ b/clientapi/routing/device.go @@ -40,6 +40,10 @@ type deviceUpdateJSON struct { DisplayName *string `json:"display_name"` } +type devicesDeleteJSON struct { + Devices []string `json:"devices"` +} + // GetDeviceByID handles /devices/{deviceID} func GetDeviceByID( req *http.Request, deviceDB *devices.Database, device *authtypes.Device, @@ -180,17 +184,15 @@ func DeleteDevices( } ctx := req.Context() - d := struct { - Devices []string `json:"devices"` - }{} + payload := devicesDeleteJSON{} - if err := json.NewDecoder(req.Body).Decode(&d); err != nil { + if err := json.NewDecoder(req.Body).Decode(&payload); err != nil { return httputil.LogThenError(req, err) } defer req.Body.Close() // nolint: errcheck - if err := deviceDB.RemoveDevices(ctx, localpart, d.Devices); err != nil { + if err := deviceDB.RemoveDevices(ctx, localpart, payload.Devices); err != nil { return httputil.LogThenError(req, err) }