diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 41db1615..6b901836 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,7 +15,7 @@ jobs: - uses: golangci/golangci-lint-action@v3 with: - version: v1.45.2 + version: v1.49.0 mod-tidy: runs-on: ubuntu-20.04 diff --git a/.golangci.yml b/.golangci.yml index 6d0de664..45f0aaa3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,3 @@ - linters: enable: - bodyclose diff --git a/Makefile b/Makefile index a4a86a90..6f2e64a2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BASE_IMAGE = golang:1.18-alpine3.15 -LINT_IMAGE = golangci/golangci-lint:v1.45.2 +LINT_IMAGE = golangci/golangci-lint:v1.49.0 NODE_IMAGE = node:16-alpine3.15 RPI32_IMAGE = balenalib/raspberrypi3:buster-run RPI64_IMAGE = balenalib/raspberrypi3-64:buster-run diff --git a/internal/conf/conf.go b/internal/conf/conf.go index eb9413ed..9841b1dd 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -1,10 +1,10 @@ +// Package conf contains the struct that holds the configuration of the software. package conf import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "os" "reflect" "strings" @@ -46,7 +46,7 @@ func loadFromFile(fpath string, conf *Conf) (bool, error) { } } - byts, err := ioutil.ReadFile(fpath) + byts, err := os.ReadFile(fpath) if err != nil { return true, err } diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index 7f4036f9..15f78248 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/base64" "io" - "io/ioutil" "os" "testing" "time" @@ -17,7 +16,7 @@ import ( ) func writeTempFile(byts []byte) (string, error) { - tmpf, err := ioutil.TempFile(os.TempDir(), "rtsp-") + tmpf, err := os.CreateTemp(os.TempDir(), "rtsp-") if err != nil { return "", err } diff --git a/internal/confwatcher/confwatcher.go b/internal/confwatcher/confwatcher.go index c5cf3ff5..c35524ab 100644 --- a/internal/confwatcher/confwatcher.go +++ b/internal/confwatcher/confwatcher.go @@ -1,3 +1,4 @@ +// Package confwatcher contains a configuration watcher. package confwatcher import ( diff --git a/internal/confwatcher/confwatcher_test.go b/internal/confwatcher/confwatcher_test.go index 92ce2d40..566dd140 100644 --- a/internal/confwatcher/confwatcher_test.go +++ b/internal/confwatcher/confwatcher_test.go @@ -1,7 +1,6 @@ package confwatcher import ( - "io/ioutil" "os" "testing" "time" @@ -10,7 +9,7 @@ import ( ) func writeTempFile(byts []byte) (string, error) { - tmpf, err := ioutil.TempFile(os.TempDir(), "confwatcher-") + tmpf, err := os.CreateTemp(os.TempDir(), "confwatcher-") if err != nil { return "", err } diff --git a/internal/core/core.go b/internal/core/core.go index da8ece9a..f3c52001 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -1,3 +1,4 @@ +// Package core contains the main struct of the software. package core import ( diff --git a/internal/core/core_test.go b/internal/core/core_test.go index fb297410..073df6da 100644 --- a/internal/core/core_test.go +++ b/internal/core/core_test.go @@ -3,7 +3,6 @@ package core import ( "bufio" "fmt" - "io/ioutil" "net" "os" "os/exec" @@ -120,7 +119,7 @@ func (c *container) wait() int { } func writeTempFile(byts []byte) (string, error) { - tmpf, err := ioutil.TempFile(os.TempDir(), "rtsp-") + tmpf, err := os.CreateTemp(os.TempDir(), "rtsp-") if err != nil { return "", err } @@ -225,15 +224,14 @@ func TestCorePathRunOnDemand(t *testing.T) { doneFile := filepath.Join(os.TempDir(), "ondemand_done") srcFile := filepath.Join(os.TempDir(), "ondemand.go") - err := ioutil.WriteFile(srcFile, []byte(` + err := os.WriteFile(srcFile, []byte(` package main import ( "os" "os/signal" "syscall" - "io/ioutil" - "github.com/aler9/gortsplib" + "github.com/aler9/gortsplib" ) func main() { @@ -261,7 +259,7 @@ func main() { signal.Notify(c, syscall.SIGINT) <-c - err = ioutil.WriteFile("`+doneFile+`", []byte(""), 0644) + err = os.WriteFile("`+doneFile+`", []byte(""), 0644) if err != nil { panic(err) } @@ -394,7 +392,7 @@ func TestCorePathRunOnReady(t *testing.T) { func TestCoreHotReloading(t *testing.T) { confPath := filepath.Join(os.TempDir(), "rtsp-conf") - err := ioutil.WriteFile(confPath, []byte("paths:\n"+ + err := os.WriteFile(confPath, []byte("paths:\n"+ " test1:\n"+ " publishUser: myuser\n"+ " publishPass: mypass\n"), @@ -421,7 +419,7 @@ func TestCoreHotReloading(t *testing.T) { require.EqualError(t, err, "bad status code: 401 (Unauthorized)") }() - err = ioutil.WriteFile(confPath, []byte("paths:\n"+ + err = os.WriteFile(confPath, []byte("paths:\n"+ " test1:\n"), 0o644) require.NoError(t, err) diff --git a/internal/core/metrics_test.go b/internal/core/metrics_test.go index cf8c7b09..c13f3759 100644 --- a/internal/core/metrics_test.go +++ b/internal/core/metrics_test.go @@ -1,7 +1,7 @@ package core import ( - "io/ioutil" + "io" "net/http" "os" "strings" @@ -68,7 +68,7 @@ func TestMetrics(t *testing.T) { defer res.Body.Close() require.Equal(t, http.StatusOK, res.StatusCode) - bo, err := ioutil.ReadAll(res.Body) + bo, err := io.ReadAll(res.Body) require.NoError(t, err) vals := make(map[string]string) diff --git a/internal/externalcmd/cmd.go b/internal/externalcmd/cmd.go index 6d21bf91..522f8f18 100644 --- a/internal/externalcmd/cmd.go +++ b/internal/externalcmd/cmd.go @@ -1,3 +1,4 @@ +// Package externalcmd allows to launch external commands. package externalcmd import ( diff --git a/internal/hls/client.go b/internal/hls/client.go index 665b19c5..7aa604c7 100644 --- a/internal/hls/client.go +++ b/internal/hls/client.go @@ -7,7 +7,7 @@ import ( "crypto/tls" "encoding/hex" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -383,7 +383,7 @@ func (c *Client) downloadSegment(innerCtx context.Context, segmentURI string) ([ return nil, fmt.Errorf("bad status code: %d", res.StatusCode) } - byts, err := ioutil.ReadAll(res.Body) + byts, err := io.ReadAll(res.Body) if err != nil { return nil, err } diff --git a/internal/hls/client_test.go b/internal/hls/client_test.go index fdffe868..92f2727a 100644 --- a/internal/hls/client_test.go +++ b/internal/hls/client_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "log" "net" "net/http" @@ -80,7 +79,7 @@ y++U32uuSFiXDcSLarfIsE992MEJLSAynbF1Rsgsr3gXbGiuToJRyxbIeVy7gwzD `) func writeTempFile(byts []byte) (string, error) { - tmpf, err := ioutil.TempFile(os.TempDir(), "rtsp-") + tmpf, err := os.CreateTemp(os.TempDir(), "rtsp-") if err != nil { return "", err } diff --git a/internal/hls/fmp4/init.go b/internal/hls/fmp4/init.go index 0be6502a..0a4ec213 100644 --- a/internal/hls/fmp4/init.go +++ b/internal/hls/fmp4/init.go @@ -1,3 +1,4 @@ +// Package fmp4 contains a fMP4 writer. package fmp4 import ( diff --git a/internal/hls/mpegts/writer.go b/internal/hls/mpegts/writer.go index c02fc95c..674ac592 100644 --- a/internal/hls/mpegts/writer.go +++ b/internal/hls/mpegts/writer.go @@ -1,3 +1,4 @@ +// Package mpegts contains a MPEG-TS writer. package mpegts import ( diff --git a/internal/hls/muxer.go b/internal/hls/muxer.go index f5f20924..d4ca8b01 100644 --- a/internal/hls/muxer.go +++ b/internal/hls/muxer.go @@ -1,3 +1,4 @@ +// Package hls contains a HLS muxer and client implementation. package hls import ( diff --git a/internal/hls/muxer_test.go b/internal/hls/muxer_test.go index bbcd535f..4d82e5c3 100644 --- a/internal/hls/muxer_test.go +++ b/internal/hls/muxer_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "regexp" "testing" "time" @@ -127,7 +126,7 @@ func TestMuxerVideoAudio(t *testing.T) { }) require.NoError(t, err) - byts, err := ioutil.ReadAll(m.File("index.m3u8", "", "", "").Body) + byts, err := io.ReadAll(m.File("index.m3u8", "", "", "").Body) require.NoError(t, err) if ca == "mpegts" { @@ -146,7 +145,7 @@ func TestMuxerVideoAudio(t *testing.T) { "stream.m3u8\n", string(byts)) } - byts, err = ioutil.ReadAll(m.File("stream.m3u8", "", "", "").Body) + byts, err = io.ReadAll(m.File("stream.m3u8", "", "", "").Body) require.NoError(t, err) var ma []string @@ -461,7 +460,7 @@ func TestMuxerVideoOnly(t *testing.T) { }) require.NoError(t, err) - byts, err := ioutil.ReadAll(m.File("index.m3u8", "", "", "").Body) + byts, err := io.ReadAll(m.File("index.m3u8", "", "", "").Body) require.NoError(t, err) if ca == "mpegts" { @@ -480,7 +479,7 @@ func TestMuxerVideoOnly(t *testing.T) { "stream.m3u8\n", string(byts)) } - byts, err = ioutil.ReadAll(m.File("stream.m3u8", "", "", "").Body) + byts, err = io.ReadAll(m.File("stream.m3u8", "", "", "").Body) require.NoError(t, err) var ma []string @@ -688,7 +687,7 @@ func TestMuxerAudioOnly(t *testing.T) { }) require.NoError(t, err) - byts, err := ioutil.ReadAll(m.File("index.m3u8", "", "", "").Body) + byts, err := io.ReadAll(m.File("index.m3u8", "", "", "").Body) require.NoError(t, err) if ca == "mpegts" { @@ -707,7 +706,7 @@ func TestMuxerAudioOnly(t *testing.T) { "stream.m3u8\n", string(byts)) } - byts, err = ioutil.ReadAll(m.File("stream.m3u8", "", "", "").Body) + byts, err = io.ReadAll(m.File("stream.m3u8", "", "", "").Body) require.NoError(t, err) var ma []string @@ -929,7 +928,7 @@ func TestMuxerDoubleRead(t *testing.T) { }) require.NoError(t, err) - byts, err := ioutil.ReadAll(m.File("stream.m3u8", "", "", "").Body) + byts, err := io.ReadAll(m.File("stream.m3u8", "", "", "").Body) require.NoError(t, err) re := regexp.MustCompile(`^#EXTM3U\n` + @@ -944,10 +943,10 @@ func TestMuxerDoubleRead(t *testing.T) { ma := re.FindStringSubmatch(string(byts)) require.NotEqual(t, 0, len(ma)) - byts1, err := ioutil.ReadAll(m.File(ma[2], "", "", "").Body) + byts1, err := io.ReadAll(m.File(ma[2], "", "", "").Body) require.NoError(t, err) - byts2, err := ioutil.ReadAll(m.File(ma[2], "", "", "").Body) + byts2, err := io.ReadAll(m.File(ma[2], "", "", "").Body) require.NoError(t, err) require.Equal(t, byts1, byts2) } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 6aad2dff..be6d381f 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -1,3 +1,4 @@ +// Package logger contains a logger implementation. package logger import ( diff --git a/internal/rlimit/rlimit_unix.go b/internal/rlimit/rlimit_unix.go index 7a09f8fc..58d15174 100644 --- a/internal/rlimit/rlimit_unix.go +++ b/internal/rlimit/rlimit_unix.go @@ -1,6 +1,7 @@ //go:build !windows // +build !windows +// Package rlimit contains a function to raise rlimit. package rlimit import ( diff --git a/internal/rpicamera/rpicamera_disabled.go b/internal/rpicamera/rpicamera_disabled.go index f23db25e..76616b9c 100644 --- a/internal/rpicamera/rpicamera_disabled.go +++ b/internal/rpicamera/rpicamera_disabled.go @@ -1,6 +1,7 @@ //go:build !rpicamera // +build !rpicamera +// Package rpicamera allows to interact with a Raspberry Pi Camera. package rpicamera import ( diff --git a/internal/rtmp/bytecounter/readwriter.go b/internal/rtmp/bytecounter/readwriter.go index f12fd6fb..53e5be33 100644 --- a/internal/rtmp/bytecounter/readwriter.go +++ b/internal/rtmp/bytecounter/readwriter.go @@ -1,3 +1,4 @@ +// Package bytecounter contains a reader/writer that allows to count bytes. package bytecounter import ( diff --git a/internal/rtmp/chunk/chunk.go b/internal/rtmp/chunk/chunk.go index 27f845d4..25e992a5 100644 --- a/internal/rtmp/chunk/chunk.go +++ b/internal/rtmp/chunk/chunk.go @@ -1,3 +1,4 @@ +// Package chunk implements RTMP chunks. package chunk import ( diff --git a/internal/rtmp/chunk/chunk2.go b/internal/rtmp/chunk/chunk2.go index 06230358..e43a69d4 100644 --- a/internal/rtmp/chunk/chunk2.go +++ b/internal/rtmp/chunk/chunk2.go @@ -5,7 +5,7 @@ import ( ) // Chunk2 is a type 2 chunk. -// Neither the stream ID nor the +// Neither the stream ID nor the // message length is included; this chunk has the same stream ID and // message length as the preceding chunk. type Chunk2 struct { diff --git a/internal/rtmp/conn.go b/internal/rtmp/conn.go index 1b47a7c2..e44a957f 100644 --- a/internal/rtmp/conn.go +++ b/internal/rtmp/conn.go @@ -1,3 +1,4 @@ +// Package rtmp implements a RTMP connection. package rtmp import ( diff --git a/internal/rtmp/h264conf/h264conf.go b/internal/rtmp/h264conf/h264conf.go index c3c499e2..56b410c9 100644 --- a/internal/rtmp/h264conf/h264conf.go +++ b/internal/rtmp/h264conf/h264conf.go @@ -1,3 +1,4 @@ +// Package h264conf contains a H264 configuration parser. package h264conf import ( diff --git a/internal/rtmp/handshake/handshake.go b/internal/rtmp/handshake/handshake.go index 4b2ea00d..a1a068e3 100644 --- a/internal/rtmp/handshake/handshake.go +++ b/internal/rtmp/handshake/handshake.go @@ -1,3 +1,4 @@ +// Package handshake contains the RTMP handshake mechanism. package handshake import ( diff --git a/internal/rtmp/message/message.go b/internal/rtmp/message/message.go index b6d78652..5883b4a3 100644 --- a/internal/rtmp/message/message.go +++ b/internal/rtmp/message/message.go @@ -1,3 +1,4 @@ +// Package message contains a RTMP message reader/writer. package message import ( diff --git a/internal/rtmp/rawmessage/message.go b/internal/rtmp/rawmessage/message.go index 2025cf2c..02768718 100644 --- a/internal/rtmp/rawmessage/message.go +++ b/internal/rtmp/rawmessage/message.go @@ -1,3 +1,4 @@ +// Package rawmessage contains a RTMP raw message reader/writer. package rawmessage import ( diff --git a/main.go b/main.go index da4f50e6..d59045d2 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// main executable. package main import (