Use unconditional strings.TrimSuffix

This commit is contained in:
Till Faelligen 2021-08-10 13:49:24 +02:00
parent e82539b371
commit 04823e8da2

View file

@ -291,10 +291,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
// If there's a trailing slash, remove it // If there's a trailing slash, remove it
eventType := vars["type"] eventType := strings.TrimSuffix(vars["type"], "/")
if strings.HasSuffix(eventType, "/") {
eventType = eventType[:len(eventType)-1]
}
eventFormat := req.URL.Query().Get("format") == "event" eventFormat := req.URL.Query().Get("format") == "event"
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat) return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat)
})).Methods(http.MethodGet, http.MethodOptions) })).Methods(http.MethodGet, http.MethodOptions)
@ -315,11 +312,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
emptyString := "" emptyString := ""
eventType := vars["eventType"] eventType := strings.TrimSuffix(vars["eventType"], "/")
// If there's a trailing slash, remove it
if strings.HasSuffix(eventType, "/") {
eventType = eventType[:len(eventType)-1]
}
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil) return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)