clean up linting

This commit is contained in:
sentriz
2019-06-27 11:45:57 +01:00
parent a3af096de1
commit 4ee0d4c6b1
10 changed files with 26 additions and 37 deletions

View File

@@ -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

View File

@@ -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{
processAsset(
c,
&file{
data: data,
path: path,
modTime: info.ModTime(),
}
if err := processAsset(c, f, outWriter); err != nil {
return errors.Wrap(err, "processing asset")
}
},
outWriter,
)
}
return nil
}

View File

@@ -1,3 +1,4 @@
//nolint:lll
package model
import (

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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", "*")

View File

@@ -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"