From 89ebc83993a85730000c9ff7cada2649bc3f8deb Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Sun, 28 May 2023 17:18:16 +0200 Subject: [PATCH] update golangci-lint (#1870) --- .github/workflows/lint.yml | 2 +- Makefile | 2 +- internal/confwatcher/confwatcher.go | 21 +++++++++++++----- internal/core/path_manager.go | 28 ++++++++++++------------ internal/core/rtmp_conn.go | 4 ++-- internal/core/rtsp_session.go | 4 ++-- internal/core/udp_source.go | 2 +- internal/formatprocessor/generic.go | 4 ++-- internal/formatprocessor/h264_test.go | 2 +- internal/formatprocessor/mpeg2audio.go | 2 +- internal/formatprocessor/mpeg4audio.go | 2 +- internal/formatprocessor/opus.go | 2 +- internal/formatprocessor/vp8.go | 2 +- internal/formatprocessor/vp9.go | 2 +- internal/rpicamera/rpicamera_disabled.go | 6 ++--- 15 files changed, 47 insertions(+), 38 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e116e4cb..6b38fc09 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: - uses: golangci/golangci-lint-action@v3 with: - version: v1.50.1 + version: v1.52.2 mod-tidy: runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index e3ad001a..ee8dc77d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BASE_IMAGE = golang:1.20-alpine3.17 -LINT_IMAGE = golangci/golangci-lint:v1.50.1 +LINT_IMAGE = golangci/golangci-lint:v1.52.2 NODE_IMAGE = node:16-alpine3.17 RPI32_IMAGE = balenalib/raspberry-pi:bullseye-run RPI64_IMAGE = balenalib/raspberrypi3-64:bullseye-run diff --git a/internal/confwatcher/confwatcher.go b/internal/confwatcher/confwatcher.go index 85b003e9..330dc772 100644 --- a/internal/confwatcher/confwatcher.go +++ b/internal/confwatcher/confwatcher.go @@ -19,6 +19,9 @@ type ConfWatcher struct { inner *fsnotify.Watcher watchedPath string + // in + terminate chan struct{} + // out signal chan struct{} done chan struct{} @@ -55,6 +58,7 @@ func New(confPath string) (*ConfWatcher, error) { w := &ConfWatcher{ inner: inner, watchedPath: absolutePath, + terminate: make(chan struct{}), signal: make(chan struct{}), done: make(chan struct{}), } @@ -66,11 +70,7 @@ func New(confPath string) (*ConfWatcher, error) { // Close closes a ConfWatcher. func (w *ConfWatcher) Close() { - go func() { - for range w.signal { - } - }() - w.inner.Close() + close(w.terminate) <-w.done } @@ -103,15 +103,24 @@ outer: previousWatchedPath = currentWatchedPath lastCalled = time.Now() - w.signal <- struct{}{} + + select { + case w.signal <- struct{}{}: + case <-w.terminate: + break outer + } } case <-w.inner.Errors: break outer + + case <-w.terminate: + break outer } } close(w.signal) + w.inner.Close() } // Watch returns a channel that is called after the configuration file has changed. diff --git a/internal/core/path_manager.go b/internal/core/path_manager.go index 34e9b350..aedbed82 100644 --- a/internal/core/path_manager.go +++ b/internal/core/path_manager.go @@ -12,22 +12,22 @@ import ( ) func pathConfCanBeUpdated(oldPathConf *conf.PathConf, newPathConf *conf.PathConf) bool { - copy := oldPathConf.Clone() + clone := oldPathConf.Clone() - copy.RPICameraBrightness = newPathConf.RPICameraBrightness - copy.RPICameraContrast = newPathConf.RPICameraContrast - copy.RPICameraSaturation = newPathConf.RPICameraSaturation - copy.RPICameraSharpness = newPathConf.RPICameraSharpness - copy.RPICameraExposure = newPathConf.RPICameraExposure - copy.RPICameraAWB = newPathConf.RPICameraAWB - copy.RPICameraDenoise = newPathConf.RPICameraDenoise - copy.RPICameraShutter = newPathConf.RPICameraShutter - copy.RPICameraMetering = newPathConf.RPICameraMetering - copy.RPICameraGain = newPathConf.RPICameraGain - copy.RPICameraEV = newPathConf.RPICameraEV - copy.RPICameraFPS = newPathConf.RPICameraFPS + clone.RPICameraBrightness = newPathConf.RPICameraBrightness + clone.RPICameraContrast = newPathConf.RPICameraContrast + clone.RPICameraSaturation = newPathConf.RPICameraSaturation + clone.RPICameraSharpness = newPathConf.RPICameraSharpness + clone.RPICameraExposure = newPathConf.RPICameraExposure + clone.RPICameraAWB = newPathConf.RPICameraAWB + clone.RPICameraDenoise = newPathConf.RPICameraDenoise + clone.RPICameraShutter = newPathConf.RPICameraShutter + clone.RPICameraMetering = newPathConf.RPICameraMetering + clone.RPICameraGain = newPathConf.RPICameraGain + clone.RPICameraEV = newPathConf.RPICameraEV + clone.RPICameraFPS = newPathConf.RPICameraFPS - return newPathConf.Equal(copy) + return newPathConf.Equal(clone) } type pathManagerHLSManager interface { diff --git a/internal/core/rtmp_conn.go b/internal/core/rtmp_conn.go index 807024ce..cd81a15b 100644 --- a/internal/core/rtmp_conn.go +++ b/internal/core/rtmp_conn.go @@ -349,7 +349,7 @@ func (c *rtmpConn) runInner(ctx context.Context) error { if !publish { return c.runRead(ctx, u) } - return c.runPublish(ctx, u) + return c.runPublish(u) } func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error { @@ -704,7 +704,7 @@ func (c *rtmpConn) findAudioFormat(stream *stream, ringBuffer *ringbuffer.RingBu return nil, nil } -func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error { +func (c *rtmpConn) runPublish(u *url.URL) error { pathName, query, rawQuery := pathNameAndQuery(u) res := c.pathManager.publisherAdd(pathPublisherAddReq{ diff --git a/internal/core/rtsp_session.go b/internal/core/rtsp_session.go index f2ce81e6..aa8496e5 100644 --- a/internal/core/rtsp_session.go +++ b/internal/core/rtsp_session.go @@ -258,7 +258,7 @@ func (s *rtspSession) onSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt } // onPlay is called by rtspServer. -func (s *rtspSession) onPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) { +func (s *rtspSession) onPlay(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) { h := make(base.Header) if s.session.State() == gortsplib.ServerSessionStatePrePlay { @@ -333,7 +333,7 @@ func (s *rtspSession) onRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.R } // onPause is called by rtspServer. -func (s *rtspSession) onPause(ctx *gortsplib.ServerHandlerOnPauseCtx) (*base.Response, error) { +func (s *rtspSession) onPause(_ *gortsplib.ServerHandlerOnPauseCtx) (*base.Response, error) { switch s.session.State() { case gortsplib.ServerSessionStatePlay: if s.onReadCmd != nil { diff --git a/internal/core/udp_source.go b/internal/core/udp_source.go index f650474a..d1665b5c 100644 --- a/internal/core/udp_source.go +++ b/internal/core/udp_source.go @@ -122,7 +122,7 @@ func (s *udpSource) Log(level logger.Level, format string, args ...interface{}) } // run implements sourceStaticImpl. -func (s *udpSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan *conf.PathConf) error { +func (s *udpSource) run(ctx context.Context, cnf *conf.PathConf, _ chan *conf.PathConf) error { s.Log(logger.Debug, "connecting") hostPort := cnf.Source[len("udp://"):] diff --git a/internal/formatprocessor/generic.go b/internal/formatprocessor/generic.go index f945d7e3..d9dc449c 100644 --- a/internal/formatprocessor/generic.go +++ b/internal/formatprocessor/generic.go @@ -34,7 +34,7 @@ func newGeneric( udpMaxPayloadSize int, forma formats.Format, generateRTPPackets bool, - log logger.Writer, + _ logger.Writer, ) (*formatProcessorGeneric, error) { if generateRTPPackets { return nil, fmt.Errorf("we don't know how to generate RTP packets of format %+v", forma) @@ -45,7 +45,7 @@ func newGeneric( }, nil } -func (t *formatProcessorGeneric) Process(unit Unit, hasNonRTSPReaders bool) error { +func (t *formatProcessorGeneric) Process(unit Unit, _ bool) error { tunit := unit.(*UnitGeneric) pkt := tunit.RTPPackets[0] diff --git a/internal/formatprocessor/h264_test.go b/internal/formatprocessor/h264_test.go index 7b2b4cf9..4d45bfb0 100644 --- a/internal/formatprocessor/h264_test.go +++ b/internal/formatprocessor/h264_test.go @@ -18,7 +18,7 @@ type testLogWriter struct { recv chan string } -func (w *testLogWriter) Log(level logger.Level, format string, args ...interface{}) { +func (w *testLogWriter) Log(_ logger.Level, format string, args ...interface{}) { w.recv <- fmt.Sprintf(format, args...) } diff --git a/internal/formatprocessor/mpeg2audio.go b/internal/formatprocessor/mpeg2audio.go index cda0cd2a..446d7005 100644 --- a/internal/formatprocessor/mpeg2audio.go +++ b/internal/formatprocessor/mpeg2audio.go @@ -40,7 +40,7 @@ func newMPEG2Audio( udpMaxPayloadSize int, forma *formats.MPEG2Audio, generateRTPPackets bool, - log logger.Writer, + _ logger.Writer, ) (*formatProcessorMPEG2Audio, error) { t := &formatProcessorMPEG2Audio{ udpMaxPayloadSize: udpMaxPayloadSize, diff --git a/internal/formatprocessor/mpeg4audio.go b/internal/formatprocessor/mpeg4audio.go index 7fd3fcd4..0473ad04 100644 --- a/internal/formatprocessor/mpeg4audio.go +++ b/internal/formatprocessor/mpeg4audio.go @@ -40,7 +40,7 @@ func newMPEG4Audio( udpMaxPayloadSize int, forma *formats.MPEG4Audio, generateRTPPackets bool, - log logger.Writer, + _ logger.Writer, ) (*formatProcessorMPEG4Audio, error) { t := &formatProcessorMPEG4Audio{ udpMaxPayloadSize: udpMaxPayloadSize, diff --git a/internal/formatprocessor/opus.go b/internal/formatprocessor/opus.go index 0a6bec95..739ef03c 100644 --- a/internal/formatprocessor/opus.go +++ b/internal/formatprocessor/opus.go @@ -40,7 +40,7 @@ func newOpus( udpMaxPayloadSize int, forma *formats.Opus, generateRTPPackets bool, - log logger.Writer, + _ logger.Writer, ) (*formatProcessorOpus, error) { t := &formatProcessorOpus{ udpMaxPayloadSize: udpMaxPayloadSize, diff --git a/internal/formatprocessor/vp8.go b/internal/formatprocessor/vp8.go index d9ee6159..3233390d 100644 --- a/internal/formatprocessor/vp8.go +++ b/internal/formatprocessor/vp8.go @@ -40,7 +40,7 @@ func newVP8( udpMaxPayloadSize int, forma *formats.VP8, generateRTPPackets bool, - log logger.Writer, + _ logger.Writer, ) (*formatProcessorVP8, error) { t := &formatProcessorVP8{ udpMaxPayloadSize: udpMaxPayloadSize, diff --git a/internal/formatprocessor/vp9.go b/internal/formatprocessor/vp9.go index 483e5e00..b0b98e46 100644 --- a/internal/formatprocessor/vp9.go +++ b/internal/formatprocessor/vp9.go @@ -40,7 +40,7 @@ func newVP9( udpMaxPayloadSize int, forma *formats.VP9, generateRTPPackets bool, - log logger.Writer, + _ logger.Writer, ) (*formatProcessorVP9, error) { t := &formatProcessorVP9{ udpMaxPayloadSize: udpMaxPayloadSize, diff --git a/internal/rpicamera/rpicamera_disabled.go b/internal/rpicamera/rpicamera_disabled.go index baa02c83..a8663320 100644 --- a/internal/rpicamera/rpicamera_disabled.go +++ b/internal/rpicamera/rpicamera_disabled.go @@ -18,8 +18,8 @@ type RPICamera struct{} // New allocates a RPICamera. func New( - params Params, - onData func(time.Duration, [][]byte), + _ Params, + _ func(time.Duration, [][]byte), ) (*RPICamera, error) { return nil, fmt.Errorf("server was compiled without support for the Raspberry Pi Camera") } @@ -29,5 +29,5 @@ func (c *RPICamera) Close() { } // ReloadParams reloads the camera parameters. -func (c *RPICamera) ReloadParams(params Params) { +func (c *RPICamera) ReloadParams(_ Params) { }