add some go-critic suggestions

This commit is contained in:
sentriz
2020-05-07 04:31:47 +01:00
parent 803a5babff
commit c65606ba1f
7 changed files with 22 additions and 22 deletions

View File

@@ -75,7 +75,7 @@ type config struct {
assetPathPrefix string assetPathPrefix string
} }
func processAsset(c config, ew *errWriter, path string) error { func processAsset(c *config, ew *errWriter, path string) error {
info, err := os.Stat(path) info, err := os.Stat(path)
if err != nil { if err != nil {
return fmt.Errorf("stating asset: %w", err) return fmt.Errorf("stating asset: %w", err)
@@ -107,8 +107,7 @@ func processAsset(c config, ew *errWriter, path string) error {
return ew.err return ew.err
} }
//nolint:errcheck func processAssets(c *config, files []string) error {
func processAssets(c config, files []string) error {
out, err := os.Create(c.outPath) out, err := os.Create(c.outPath)
if err != nil { if err != nil {
return fmt.Errorf("creating out path: %w", err) return fmt.Errorf("creating out path: %w", err)
@@ -144,7 +143,7 @@ func main() {
if *outPath == "" { if *outPath == "" {
log.Fatalln("invalid arguments. see -h") log.Fatalln("invalid arguments. see -h")
} }
c := config{ c := &config{
packageName: *pkgName, packageName: *pkgName,
outPath: *outPath, outPath: *outPath,
tagList: *tagList, tagList: *tagList,

View File

@@ -236,7 +236,8 @@ type Flash struct {
Type FlashType Type FlashType
} }
//nolint:gochecknoinits //nolint:gochecknoinits // for now I think it's nice that our types and their
// gob registrations are next to each other, in case there's more added later)
func init() { func init() {
gob.Register(&Flash{}) gob.Register(&Flash{})
} }

View File

@@ -82,7 +82,7 @@ func (c *Controller) ServeUploadPlaylist(r *http.Request) *Response {
} }
func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response { func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response {
if err := r.ParseMultipartForm((1 << 10) * 24); nil != err { if err := r.ParseMultipartForm((1 << 10) * 24); err != nil {
return &Response{ return &Response{
err: "couldn't parse mutlipart", err: "couldn't parse mutlipart",
code: 500, code: 500,

View File

@@ -53,7 +53,7 @@ func runQueryCases(t *testing.T, h handlerSubsonic, cases []*queryCase) {
// convert test name to query case path // convert test name to query case path
snake := testCamelExpr.ReplaceAllString(t.Name(), "${1}_${2}") snake := testCamelExpr.ReplaceAllString(t.Name(), "${1}_${2}")
lower := strings.ToLower(snake) lower := strings.ToLower(snake)
relPath := strings.Replace(lower, "/", "_", -1) relPath := strings.ReplaceAll(lower, "/", "_")
absExpPath := path.Join(testDataDir, relPath) absExpPath := path.Join(testDataDir, relPath)
// read case to differ with handler result // read case to differ with handler result
expected, err := jd.ReadJsonFile(absExpPath) expected, err := jd.ReadJsonFile(absExpPath)

View File

@@ -1,5 +1,5 @@
// Package db provides database helpers and models // Package db provides database helpers and models
//nolint:lll //nolint:lll // struct tags get very long and can't be split
package db package db
// see this db fiddle to mess around with the schema // see this db fiddle to mess around with the schema
@@ -15,7 +15,7 @@ import (
) )
func splitInt(in, sep string) []int { func splitInt(in, sep string) []int {
if len(in) == 0 { if in == "" {
return []int{} return []int{}
} }
parts := strings.Split(in, sep) parts := strings.Split(in, sep)

View File

@@ -15,6 +15,7 @@ import (
const ( const (
buffLen = 4096 buffLen = 4096
ffmpegPath = "/usr/bin/ffmpeg"
) )
type Profile struct { type Profile struct {
@@ -34,7 +35,7 @@ func Profiles() map[string]Profile {
} }
// copy command output to http response body using io.copy (simpler, but may increase ttfb) // copy command output to http response body using io.copy (simpler, but may increase ttfb)
//nolint:deadcode,unused //nolint:deadcode,unused // function may be switched later
func copyCmdOutput(out, cache io.Writer, pipeReader io.Reader) { func copyCmdOutput(out, cache io.Writer, pipeReader io.Reader) {
// set up a multiwriter to feed the command output // set up a multiwriter to feed the command output
// to both cache file and http response // to both cache file and http response
@@ -46,7 +47,7 @@ func copyCmdOutput(out, cache io.Writer, pipeReader io.Reader) {
} }
// copy command output to http response manually with a buffer (should reduce ttfb) // copy command output to http response manually with a buffer (should reduce ttfb)
//nolint:deadcode,unused //nolint:deadcode,unused // function may be switched later
func writeCmdOutput(out, cache io.Writer, pipeReader io.ReadCloser) { func writeCmdOutput(out, cache io.Writer, pipeReader io.ReadCloser) {
buffer := make([]byte, buffLen) buffer := make([]byte, buffLen)
for { for {
@@ -94,7 +95,8 @@ func ffmpegCommand(filePath string, profile Profile, bitrate string) *exec.Cmd {
) )
} }
args = append(args, "-f", profile.Format, "-") args = append(args, "-f", profile.Format, "-")
return exec.Command("/usr/bin/ffmpeg", args...) //nolint:gosec return exec.Command(ffmpegPath, args...) //nolint:gosec // can't see a way for this be abused
// but please do let me know if you see otherwise
} }
func Encode(out io.Writer, trackPath, cachePath string, profile Profile, bitrate string) error { func Encode(out io.Writer, trackPath, cachePath string, profile Profile, bitrate string) error {

View File

@@ -180,7 +180,6 @@ func (j *Jukebox) doUpdateSpeaker(su updateSpeaker) error {
return err return err
} }
j.Lock() j.Lock()
{
j.info = &strmInfo{} j.info = &strmInfo{}
j.info.strm = streamer.(beep.StreamSeekCloser) j.info.strm = streamer.(beep.StreamSeekCloser)
j.info.ctrlStrmr.Streamer = beep.Resample( j.info.ctrlStrmr.Streamer = beep.Resample(
@@ -188,7 +187,6 @@ func (j *Jukebox) doUpdateSpeaker(su updateSpeaker) error {
j.sr, j.info.strm, j.sr, j.info.strm,
) )
j.info.format = format j.info.format = format
}
j.Unlock() j.Unlock()
speaker.Play(beep.Seq(&j.info.ctrlStrmr, beep.Callback(func() { speaker.Play(beep.Seq(&j.info.ctrlStrmr, beep.Callback(func() {
j.speaker <- updateSpeaker{su.index + 1} j.speaker <- updateSpeaker{su.index + 1}