diff --git a/.golangci.yml b/.golangci.yml index 882ed26..96771d1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,18 +12,3 @@ issues: - text: "weak cryptographic primitive" linters: - gosec - - path: model/model\.go - linters: - - lll - - path: server/handler/ - source: "next http.HandlerFunc" - linters: - - interfacer - - path: server/handler/ - source: "session.Save" - linters: - - errcheck - - path: server/handler/ - source: "w.Write" - linters: - - errcheck diff --git a/cmd/gonicembed/main.go b/cmd/gonicembed/main.go index 8467065..cb596f2 100644 --- a/cmd/gonicembed/main.go +++ b/cmd/gonicembed/main.go @@ -56,7 +56,8 @@ type file struct { modTime time.Time } -func processAsset(c *config, f *file, out io.Writer) error { +//nolint:errcheck +func processAsset(c *config, f *file, out io.Writer) { out.Write([]byte(fmt.Sprintf(assetHeader, strings.TrimPrefix(f.path, c.assetPathPrefix), f.modTime.Unix(), @@ -73,9 +74,9 @@ func processAsset(c *config, f *file, out io.Writer) error { } fmt.Fprintln(out) } - return nil } +//nolint:errcheck func processAssets(c *config, files []string) error { outWriter, err := os.Create(c.outPath) if err != nil { @@ -99,14 +100,15 @@ func processAssets(c *config, files []string) error { if err != nil { return errors.Wrap(err, "opening asset") } - f := &file{ - data: data, - path: path, - modTime: info.ModTime(), - } - if err := processAsset(c, f, outWriter); err != nil { - return errors.Wrap(err, "processing asset") - } + processAsset( + c, + &file{ + data: data, + path: path, + modTime: info.ModTime(), + }, + outWriter, + ) } return nil } diff --git a/model/model.go b/model/model.go index 616641f..e4677d3 100644 --- a/model/model.go +++ b/model/model.go @@ -1,3 +1,4 @@ +//nolint:lll package model import ( diff --git a/scanner/scanner.go b/scanner/scanner.go index 6023ae1..c7c549a 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -137,10 +137,9 @@ func (s *Scanner) Start() error { } // delete folders not on filesystem var folders []*model.Album - err = s.tx. + s.tx. Select("id"). - Find(&folders). - Error + Find(&folders) for _, folder := range folders { _, ok := s.seenFolders[folder.ID] if !ok { diff --git a/server/handler/construct_sub_by_folder.go b/server/handler/construct_sub_by_folder.go index bc89258..9930cb0 100644 --- a/server/handler/construct_sub_by_folder.go +++ b/server/handler/construct_sub_by_folder.go @@ -18,7 +18,7 @@ func newAlbumByFolder(f *model.Album) *subsonic.Album { } } -func newTCAlbumByFolder(f *model.Album, parent *model.Album) *subsonic.TrackChild { +func newTCAlbumByFolder(f *model.Album) *subsonic.TrackChild { trCh := &subsonic.TrackChild{ ID: f.ID, IsDir: true, diff --git a/server/handler/handler_sub_by_folder.go b/server/handler/handler_sub_by_folder.go index 5d8a2ad..9e7297c 100644 --- a/server/handler/handler_sub_by_folder.go +++ b/server/handler/handler_sub_by_folder.go @@ -73,8 +73,7 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) { Where("parent_id = ?", id). Find(&childFolders) for _, c := range childFolders { - childrenObj = append(childrenObj, - newTCAlbumByFolder(c, folder)) + childrenObj = append(childrenObj, newTCAlbumByFolder(c)) } // // start looking for child childTracks in the current dir @@ -150,8 +149,7 @@ func (c *Controller) GetAlbumList(w http.ResponseWriter, r *http.Request) { sub := subsonic.NewResponse() sub.Albums = &subsonic.Albums{} for _, folder := range folders { - sub.Albums.List = append(sub.Albums.List, - newAlbumByFolder(folder)) + sub.Albums.List = append(sub.Albums.List, newAlbumByFolder(folder)) } respond(w, r, sub) } @@ -181,14 +179,12 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) { // search "albums" var albums []*model.Album c.DB. - Preload("Parent"). Where("tag_artist_id IS NOT NULL AND right_path LIKE ?", query). Offset(getIntParamOr(r, "albumOffset", 0)). Limit(getIntParamOr(r, "albumCount", 20)). Find(&albums) for _, a := range albums { - results.Albums = append(results.Albums, - newTCAlbumByFolder(a, a.Parent)) + results.Albums = append(results.Albums, newTCAlbumByFolder(a)) } // // search tracks diff --git a/server/handler/middleware_admin.go b/server/handler/middleware_admin.go index 25bf3b0..2e79dc8 100644 --- a/server/handler/middleware_admin.go +++ b/server/handler/middleware_admin.go @@ -9,6 +9,7 @@ import ( "github.com/sentriz/gonic/model" ) +//nolint:interfacer func (c *Controller) WithSession(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { session, _ := c.SessDB.Get(r, "gonic") @@ -17,6 +18,7 @@ func (c *Controller) WithSession(next http.HandlerFunc) http.HandlerFunc { } } +//nolint:interfacer func (c *Controller) WithUserSession(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // session exists at this point @@ -43,6 +45,7 @@ func (c *Controller) WithUserSession(next http.HandlerFunc) http.HandlerFunc { } } +//nolint:interfacer func (c *Controller) WithAdminSession(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // session and user exist at this point diff --git a/server/handler/middleware_common.go b/server/handler/middleware_common.go index 901b51b..9f6a999 100644 --- a/server/handler/middleware_common.go +++ b/server/handler/middleware_common.go @@ -5,6 +5,7 @@ import ( "net/http" ) +//nolint:interfacer func (c *Controller) WithLogging(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { log.Printf("connection from `%s` for `%s`", r.RemoteAddr, r.URL) diff --git a/server/handler/middleware_sub.go b/server/handler/middleware_sub.go index e19cac3..3c06811 100644 --- a/server/handler/middleware_sub.go +++ b/server/handler/middleware_sub.go @@ -41,6 +41,7 @@ func checkCredentialsBasic(password, given string) bool { return password == given } +//nolint:interfacer func (c *Controller) WithValidSubsonicArgs(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { err := checkHasAllParams(r.URL.Query()) @@ -79,6 +80,7 @@ func (c *Controller) WithValidSubsonicArgs(next http.HandlerFunc) http.HandlerFu } } +//nolint:interfacer func (c *Controller) WithCORS(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") diff --git a/server/setup_admin.go b/server/setup_admin.go index 83bcc2c..ca28313 100644 --- a/server/setup_admin.go +++ b/server/setup_admin.go @@ -7,7 +7,7 @@ import ( "path/filepath" "time" - "github.com/Masterminds/sprig" + "github.com/Masterminds/sprig" //nolint:typecheck "github.com/dustin/go-humanize" "github.com/gorilla/securecookie" "github.com/pkg/errors"