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" - text: "weak cryptographic primitive"
linters: linters:
- gosec - 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 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, out.Write([]byte(fmt.Sprintf(assetHeader,
strings.TrimPrefix(f.path, c.assetPathPrefix), strings.TrimPrefix(f.path, c.assetPathPrefix),
f.modTime.Unix(), f.modTime.Unix(),
@@ -73,9 +74,9 @@ func processAsset(c *config, f *file, out io.Writer) error {
} }
fmt.Fprintln(out) fmt.Fprintln(out)
} }
return nil
} }
//nolint:errcheck
func processAssets(c *config, files []string) error { func processAssets(c *config, files []string) error {
outWriter, err := os.Create(c.outPath) outWriter, err := os.Create(c.outPath)
if err != nil { if err != nil {
@@ -99,14 +100,15 @@ func processAssets(c *config, files []string) error {
if err != nil { if err != nil {
return errors.Wrap(err, "opening asset") return errors.Wrap(err, "opening asset")
} }
f := &file{ processAsset(
data: data, c,
path: path, &file{
modTime: info.ModTime(), data: data,
} path: path,
if err := processAsset(c, f, outWriter); err != nil { modTime: info.ModTime(),
return errors.Wrap(err, "processing asset") },
} outWriter,
)
} }
return nil return nil
} }

View File

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

View File

@@ -137,10 +137,9 @@ func (s *Scanner) Start() error {
} }
// delete folders not on filesystem // delete folders not on filesystem
var folders []*model.Album var folders []*model.Album
err = s.tx. s.tx.
Select("id"). Select("id").
Find(&folders). Find(&folders)
Error
for _, folder := range folders { for _, folder := range folders {
_, ok := s.seenFolders[folder.ID] _, ok := s.seenFolders[folder.ID]
if !ok { 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{ trCh := &subsonic.TrackChild{
ID: f.ID, ID: f.ID,
IsDir: true, IsDir: true,

View File

@@ -73,8 +73,7 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) {
Where("parent_id = ?", id). Where("parent_id = ?", id).
Find(&childFolders) Find(&childFolders)
for _, c := range childFolders { for _, c := range childFolders {
childrenObj = append(childrenObj, childrenObj = append(childrenObj, newTCAlbumByFolder(c))
newTCAlbumByFolder(c, folder))
} }
// //
// start looking for child childTracks in the current dir // 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 := subsonic.NewResponse()
sub.Albums = &subsonic.Albums{} sub.Albums = &subsonic.Albums{}
for _, folder := range folders { for _, folder := range folders {
sub.Albums.List = append(sub.Albums.List, sub.Albums.List = append(sub.Albums.List, newAlbumByFolder(folder))
newAlbumByFolder(folder))
} }
respond(w, r, sub) respond(w, r, sub)
} }
@@ -181,14 +179,12 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) {
// search "albums" // search "albums"
var albums []*model.Album var albums []*model.Album
c.DB. c.DB.
Preload("Parent").
Where("tag_artist_id IS NOT NULL AND right_path LIKE ?", query). Where("tag_artist_id IS NOT NULL AND right_path LIKE ?", query).
Offset(getIntParamOr(r, "albumOffset", 0)). Offset(getIntParamOr(r, "albumOffset", 0)).
Limit(getIntParamOr(r, "albumCount", 20)). Limit(getIntParamOr(r, "albumCount", 20)).
Find(&albums) Find(&albums)
for _, a := range albums { for _, a := range albums {
results.Albums = append(results.Albums, results.Albums = append(results.Albums, newTCAlbumByFolder(a))
newTCAlbumByFolder(a, a.Parent))
} }
// //
// search tracks // search tracks

View File

@@ -9,6 +9,7 @@ import (
"github.com/sentriz/gonic/model" "github.com/sentriz/gonic/model"
) )
//nolint:interfacer
func (c *Controller) WithSession(next http.HandlerFunc) http.HandlerFunc { func (c *Controller) WithSession(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
session, _ := c.SessDB.Get(r, "gonic") 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 { func (c *Controller) WithUserSession(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
// session exists at this point // 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 { func (c *Controller) WithAdminSession(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
// session and user exist at this point // session and user exist at this point

View File

@@ -5,6 +5,7 @@ import (
"net/http" "net/http"
) )
//nolint:interfacer
func (c *Controller) WithLogging(next http.HandlerFunc) http.HandlerFunc { func (c *Controller) WithLogging(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
log.Printf("connection from `%s` for `%s`", r.RemoteAddr, r.URL) 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 return password == given
} }
//nolint:interfacer
func (c *Controller) WithValidSubsonicArgs(next http.HandlerFunc) http.HandlerFunc { func (c *Controller) WithValidSubsonicArgs(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
err := checkHasAllParams(r.URL.Query()) 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 { func (c *Controller) WithCORS(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")

View File

@@ -7,7 +7,7 @@ import (
"path/filepath" "path/filepath"
"time" "time"
"github.com/Masterminds/sprig" "github.com/Masterminds/sprig" //nolint:typecheck
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/gorilla/securecookie" "github.com/gorilla/securecookie"
"github.com/pkg/errors" "github.com/pkg/errors"