update golangci lint linter list

This commit is contained in:
sentriz
2020-05-02 04:22:26 +01:00
parent fc6f39bbfe
commit b02ade3415
14 changed files with 53 additions and 31 deletions

View File

@@ -1,7 +1,9 @@
// Package ctrladmin provides HTTP handlers for admin UI
package ctrladmin
import (
"encoding/gob"
"errors"
"fmt"
"html/template"
"log"
@@ -150,7 +152,6 @@ type (
handlerAdminRaw func(w http.ResponseWriter, r *http.Request)
)
//nolint:gocognit
func (c *Controller) H(h handlerAdmin) http.Handler {
// TODO: break this up a bit
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -272,26 +273,33 @@ func sessLogSave(s *sessions.Session, w http.ResponseWriter, r *http.Request) {
// ## begin validation
// ## begin validation
var (
errValiNoUsername = errors.New("please enter the password twice")
errValiPasswordAllFields = errors.New("please enter the password twice")
errValiPasswordsNotSame = errors.New("passwords entered were not the same")
errValiKeysAllFields = errors.New("please enter the api key and secret")
)
func validateUsername(username string) error {
if username == "" {
return fmt.Errorf("please enter the username")
return errValiNoUsername
}
return nil
}
func validatePasswords(pOne, pTwo string) error {
if pOne == "" || pTwo == "" {
return fmt.Errorf("please enter the password twice")
return errValiPasswordAllFields
}
if !(pOne == pTwo) {
return fmt.Errorf("the two passwords entered were not the same")
return errValiPasswordsNotSame
}
return nil
}
func validateAPIKey(apiKey, secret string) error {
if apiKey == "" || secret == "" {
return fmt.Errorf("please enter both the api key and secret")
return errValiKeysAllFields
}
return nil
}

View File

@@ -2,6 +2,7 @@ package ctrladmin
import (
"bufio"
"errors"
"fmt"
"mime/multipart"
"net/http"
@@ -12,6 +13,10 @@ import (
"go.senan.xyz/gonic/server/db"
)
var (
errPlaylistNoMatch = errors.New("couldn't match track")
)
func playlistParseLine(c *Controller, path string) (int, error) {
if strings.HasPrefix(path, "#") || strings.TrimSpace(path) == "" {
return 0, nil
@@ -25,7 +30,7 @@ func playlistParseLine(c *Controller, path string) (int, error) {
err := query.First(&track).Error
switch {
case gorm.IsRecordNotFoundError(err):
return 0, fmt.Errorf("couldn't match track %q", path)
return 0, fmt.Errorf("%v: %w", err, errPlaylistNoMatch)
case err != nil:
return 0, fmt.Errorf("while matching: %w", err)
default: