diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8ed03e9b..8448101f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,7 +17,7 @@ jobs: - uses: golangci/golangci-lint-action@v2 with: - version: v1.33 + version: v1.38 go-mod-tidy: name: go-mod-tidy diff --git a/.golangci.yml b/.golangci.yml index 882d79e4..279a5a83 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,7 @@ linters: enable: + - gocritic - gofmt - golint - misspell diff --git a/Makefile b/Makefile index 049080a6..92d4b589 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BASE_IMAGE = golang:1.15-alpine3.12 -LINT_IMAGE = golangci/golangci-lint:v1.33.0 +LINT_IMAGE = golangci/golangci-lint:v1.38.0 .PHONY: $(shell ls) diff --git a/internal/clientrtmp/client.go b/internal/clientrtmp/client.go index acaa1d90..856985fd 100644 --- a/internal/clientrtmp/client.go +++ b/internal/clientrtmp/client.go @@ -180,8 +180,7 @@ func (c *Client) runRead() { res := <-resc if res.Err != nil { - switch res.Err.(type) { - case client.ErrAuthCritical: + if _, ok := res.Err.(client.ErrAuthCritical); ok { // wait some seconds to stop brute force attacks select { case <-time.After(pauseAfterAuthError): @@ -453,8 +452,7 @@ func (c *Client) runPublish() { res := <-resc if res.Err != nil { - switch res.Err.(type) { - case client.ErrAuthCritical: + if _, ok := res.Err.(client.ErrAuthCritical); ok { // wait some seconds to stop brute force attacks select { case <-time.After(pauseAfterAuthError): diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index 4d6746bb..c51f9a33 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -157,7 +157,7 @@ paths: encryptedConf := func() string { var secretKey [32]byte - copy(secretKey[:], key[:]) + copy(secretKey[:], key) var nonce [24]byte if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil { diff --git a/internal/conf/path.go b/internal/conf/path.go index b09481f8..b99487f7 100644 --- a/internal/conf/path.go +++ b/internal/conf/path.go @@ -120,10 +120,11 @@ func (pconf *PathConf) fillAndCheck(name string) error { pconf.Source = "record" } - if pconf.Source == "record" { + switch { + case pconf.Source == "record": - } else if strings.HasPrefix(pconf.Source, "rtsp://") || - strings.HasPrefix(pconf.Source, "rtsps://") { + case strings.HasPrefix(pconf.Source, "rtsp://") || + strings.HasPrefix(pconf.Source, "rtsps://"): if pconf.Regexp != nil { return fmt.Errorf("a path with a regular expression (or path 'all') cannot have a RTSP source; use another path") } @@ -161,7 +162,7 @@ func (pconf *PathConf) fillAndCheck(name string) error { return fmt.Errorf("unsupported protocol '%s'", pconf.SourceProtocol) } - } else if strings.HasPrefix(pconf.Source, "rtmp://") { + case strings.HasPrefix(pconf.Source, "rtmp://"): if pconf.Regexp != nil { return fmt.Errorf("a path with a regular expression (or path 'all') cannot have a RTMP source; use another path") } @@ -183,7 +184,7 @@ func (pconf *PathConf) fillAndCheck(name string) error { } } - } else if pconf.Source == "redirect" { + case pconf.Source == "redirect": if pconf.SourceRedirect == "" { return fmt.Errorf("source redirect must be filled") } @@ -193,7 +194,7 @@ func (pconf *PathConf) fillAndCheck(name string) error { return fmt.Errorf("'%s' is not a valid RTSP url", pconf.SourceRedirect) } - } else { + default: return fmt.Errorf("invalid source: '%s'", pconf.Source) } diff --git a/internal/confenv/confenv.go b/internal/confenv/confenv.go index d7861510..f9717acf 100644 --- a/internal/confenv/confenv.go +++ b/internal/confenv/confenv.go @@ -12,8 +12,7 @@ import ( func load(env map[string]string, envKey string, rv reflect.Value) error { rt := rv.Type() - switch rt { - case reflect.TypeOf(time.Duration(0)): + if rt == reflect.TypeOf(time.Duration(0)) { if ev, ok := env[envKey]; ok { d, err := time.ParseDuration(ev) if err != nil { diff --git a/internal/path/path.go b/internal/path/path.go index 4b9d11f9..9393c854 100644 --- a/internal/path/path.go +++ b/internal/path/path.go @@ -556,12 +556,10 @@ func (pa *Path) fixedPublisherStart() { pa.sourceState = sourceStateWaitingDescribe } - } else { // reset timer - if pa.sourceCloseTimerStarted { - pa.sourceCloseTimer.Stop() - pa.sourceCloseTimer = time.NewTimer(pa.conf.SourceOnDemandCloseAfter) - } + } else if pa.sourceCloseTimerStarted { + pa.sourceCloseTimer.Stop() + pa.sourceCloseTimer = time.NewTimer(pa.conf.SourceOnDemandCloseAfter) } } @@ -579,12 +577,10 @@ func (pa *Path) fixedPublisherStart() { pa.sourceState = sourceStateWaitingDescribe } - } else { // reset timer - if pa.runOnDemandCloseTimerStarted { - pa.runOnDemandCloseTimer.Stop() - pa.runOnDemandCloseTimer = time.NewTimer(pa.conf.RunOnDemandCloseAfter) - } + } else if pa.runOnDemandCloseTimerStarted { + pa.runOnDemandCloseTimer.Stop() + pa.runOnDemandCloseTimer = time.NewTimer(pa.conf.RunOnDemandCloseAfter) } } } diff --git a/internal/rtmputils/metadata.go b/internal/rtmputils/metadata.go index 7c5ce503..ec1473eb 100644 --- a/internal/rtmputils/metadata.go +++ b/internal/rtmputils/metadata.go @@ -68,8 +68,7 @@ func ReadMetadata(conn *Conn) (*gortsplib.Track, *gortsplib.Track, error) { } case string: - switch vt { - case "avc1": + if vt == "avc1" { return true, nil } } @@ -97,8 +96,7 @@ func ReadMetadata(conn *Conn) (*gortsplib.Track, *gortsplib.Track, error) { } case string: - switch vt { - case "mp4a": + if vt == "mp4a" { return true, nil } } diff --git a/main_clientrtsp_test.go b/main_clientrtsp_test.go index f336fc08..5715e17d 100644 --- a/main_clientrtsp_test.go +++ b/main_clientrtsp_test.go @@ -421,8 +421,7 @@ func TestClientRTSPAutomaticProtocol(t *testing.T) { require.Equal(t, true, ok) defer p.close() - switch source { - case "ffmpeg": + if source == "ffmpeg" { cnt1, err := newContainer("ffmpeg", "source", []string{ "-re", "-stream_loop", "-1",