From c05b92d9246175e6240d07843ad661ed1c0ff371 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 24 Jul 2020 20:33:54 +0100 Subject: [PATCH] make linter happy --- cmd/gonic/main.go | 2 +- server/ctrlsubsonic/handlers_raw.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/gonic/main.go b/cmd/gonic/main.go index 0c7b121..5056f17 100644 --- a/cmd/gonic/main.go +++ b/cmd/gonic/main.go @@ -60,7 +60,7 @@ func main() { log.Fatalf("couldn't create cache path: %v\n", err) } } - coverCachePath := path.Join(*cachePath, "covers") + coverCachePath := path.Join(*cachePath, coverCachePrefix) if _, err := os.Stat(coverCachePath); os.IsNotExist(err) { if err := os.MkdirAll(coverCachePath, os.ModePerm); err != nil { log.Fatalf("couldn't create cover cache path: %v\n", err) diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index 6700897..c68fd2e 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -1,6 +1,7 @@ package ctrlsubsonic import ( + "errors" "fmt" "io" "log" @@ -61,6 +62,11 @@ const ( coverCacheFormat = "png" ) +var ( + errCoverNotFound = errors.New("could not find a cover with that id") + errCoverEmpty = errors.New("no cover found for that folder") +) + func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) { folder := &db.Album{} err := dbc.DB. @@ -68,10 +74,10 @@ func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) { First(folder, id). Error if gorm.IsRecordNotFoundError(err) { - return "", fmt.Errorf("could not find a cover with that id") + return "", errCoverNotFound } if folder.Cover == "" { - return "", fmt.Errorf("no cover found for that folder") + return "", errCoverEmpty } return path.Join( musicPath, @@ -84,7 +90,7 @@ func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) { func coverScaleAndSave(absPath, cachePath string, size int) error { src, err := imaging.Open(absPath) if err != nil { - return fmt.Errorf("resizing `%s`: %v", absPath, err) + return fmt.Errorf("resizing `%s`: %w", absPath, err) } width := size if width > src.Bounds().Dx() { @@ -93,7 +99,7 @@ func coverScaleAndSave(absPath, cachePath string, size int) error { } err = imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath) if err != nil { - return fmt.Errorf("caching `%s`: %v", cachePath, err) + return fmt.Errorf("caching `%s`: %w", cachePath, err) } return nil }