resolve linter issues

This commit is contained in:
David Christofas
2021-02-25 14:53:56 +01:00
parent 0802e8aac3
commit 902977cb60
4 changed files with 28 additions and 6 deletions
+10 -3
View File
@@ -1,6 +1,7 @@
package svc
import (
"io"
"net/http"
"strings"
@@ -57,7 +58,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
if err != nil {
g.log.Error().Err(err).Msg("could not create Request")
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
mustWrite(g.log, w, []byte(err.Error()))
return
}
@@ -74,7 +75,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
if err != nil {
g.log.Error().Err(err).Msg("could not get thumbnail")
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
mustWrite(g.log, w, []byte(err.Error()))
return
}
@@ -85,7 +86,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", rsp.GetMimetype())
w.WriteHeader(http.StatusOK)
w.Write(rsp.Thumbnail)
mustWrite(g.log, w, rsp.Thumbnail)
}
func extensionToFiletype(ext string) thumbnails.GetRequest_FileType {
@@ -95,3 +96,9 @@ func extensionToFiletype(ext string) thumbnails.GetRequest_FileType {
}
return thumbnails.GetRequest_FileType(val)
}
func mustWrite(logger log.Logger, w io.Writer, val []byte) {
if _, err := w.Write(val); err != nil {
logger.Error().Err(err).Msg("could not write response")
}
}