Browse Source

update golangci-lint

pull/429/head
aler9 4 years ago
parent
commit
99323ba740
  1. 1
      .golangci.yml
  2. 16
      Makefile
  3. 2
      internal/hlsconverter/converter.go
  4. 1
      internal/hlsserver/server.go
  5. 2
      internal/logger/logger.go
  6. 1
      internal/metrics/metrics.go
  7. 3
      internal/path/path.go
  8. 2
      internal/pathman/pathman.go
  9. 1
      internal/pprof/pprof.go
  10. 1
      internal/rtcpsenderset/rtcpsenderset.go
  11. 5
      internal/rtmpconn/conn.go
  12. 1
      internal/rtmpserver/server.go
  13. 2
      internal/rtmpsource/source.go
  14. 2
      internal/rtspconn/conn.go
  15. 1
      internal/rtspserver/server.go
  16. 1
      internal/rtspsession/session.go
  17. 2
      internal/rtspsource/source.go
  18. 3
      main.go
  19. 2
      main_rtspreadpub_test.go
  20. 10
      main_test.go

1
.golangci.yml

@ -6,6 +6,7 @@ linters: @@ -6,6 +6,7 @@ linters:
- gochecknoinits
- gocritic
- gofmt
- gofumpt
- golint
- misspell
- prealloc

16
Makefile

@ -26,12 +26,20 @@ $(blank) @@ -26,12 +26,20 @@ $(blank)
endef
mod-tidy:
docker run --rm -it -v $(PWD):/s amd64/$(BASE_IMAGE) \
sh -c "apk add git && cd /s && GOPROXY=direct go get && go mod tidy"
docker run --rm -it -v $(PWD):/s -w /s amd64/$(BASE_IMAGE) \
sh -c "apk add git && GOPROXY=direct go get && go mod tidy"
define DOCKERFILE_FORMAT
FROM $(BASE_IMAGE)
RUN apk add --no-cache git
RUN GO111MODULE=on go get mvdan.cc/gofumpt
endef
export DOCKERFILE_FORMAT
format:
docker run --rm -it -v $(PWD):/s amd64/$(BASE_IMAGE) \
sh -c "cd /s && find . -type f -name '*.go' | xargs gofmt -l -w -s"
echo "$$DOCKERFILE_FORMAT" | docker build -q . -f - -t temp
docker run --rm -it -v $(PWD):/s -w /s temp \
sh -c "find . -type f -name '*.go' | xargs gofumpt -l -w"
define DOCKERFILE_TEST
FROM amd64/$(BASE_IMAGE)

2
internal/hlsconverter/converter.go

@ -162,7 +162,6 @@ func New( @@ -162,7 +162,6 @@ func New(
pathName string,
pathMan PathMan,
parent Parent) *Converter {
ctx, ctxCancel := context.WithCancel(ctxParent)
c := &Converter{
@ -425,7 +424,6 @@ func (c *Converter) runInner(innerCtx context.Context) error { @@ -425,7 +424,6 @@ func (c *Converter) runInner(innerCtx context.Context) error {
}
c.tsMutex.Unlock()
}
} else {
if !curTSFile.firstPacketWritten {
continue

1
internal/hlsserver/server.go

@ -51,7 +51,6 @@ func New( @@ -51,7 +51,6 @@ func New(
pathMan *pathman.PathManager,
parent Parent,
) (*Server, error) {
ln, err := net.Listen("tcp", address)
if err != nil {
return nil, err

2
internal/logger/logger.go

@ -57,7 +57,7 @@ func New(level Level, destinations map[Destination]struct{}, filePath string) (* @@ -57,7 +57,7 @@ func New(level Level, destinations map[Destination]struct{}, filePath string) (*
if _, ok := destinations[DestinationFile]; ok {
var err error
lh.file, err = os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
lh.file, err = os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
lh.Close()
return nil, err

1
internal/metrics/metrics.go

@ -38,7 +38,6 @@ func New( @@ -38,7 +38,6 @@ func New(
stats *stats.Stats,
parent Parent,
) (*Metrics, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err

3
internal/path/path.go

@ -117,7 +117,6 @@ func New( @@ -117,7 +117,6 @@ func New(
wg *sync.WaitGroup,
stats *stats.Stats,
parent Parent) *Path {
ctx, ctxCancel := context.WithCancel(ctxParent)
pa := &Path{
@ -171,7 +170,6 @@ func (pa *Path) run() { @@ -171,7 +170,6 @@ func (pa *Path) run() {
if pa.conf.Source == "redirect" {
pa.source = &sourceRedirect{}
} else if pa.hasExternalSource() && !pa.conf.SourceOnDemand {
pa.startExternalSource()
}
@ -339,7 +337,6 @@ func (pa *Path) startExternalSource() { @@ -339,7 +337,6 @@ func (pa *Path) startExternalSource() {
&pa.sourceWg,
pa.stats,
pa)
} else if strings.HasPrefix(pa.conf.Source, "rtmp://") {
pa.source = rtmpsource.New(
pa.ctx,

2
internal/pathman/pathman.go

@ -76,7 +76,6 @@ func New( @@ -76,7 +76,6 @@ func New(
pathConfs map[string]*conf.PathConf,
stats *stats.Stats,
parent Parent) *PathManager {
ctx, ctxCancel := context.WithCancel(ctxParent)
pm := &PathManager{
@ -361,7 +360,6 @@ func (pm *PathManager) authenticate( @@ -361,7 +360,6 @@ func (pm *PathManager) authenticate(
pathUser string,
pathPass string,
) error {
// validate ip
if pathIPs != nil && ip != nil {
if !ipEqualOrInRange(ip, pathIPs) {

1
internal/pprof/pprof.go

@ -27,7 +27,6 @@ func New( @@ -27,7 +27,6 @@ func New(
address string,
parent Parent,
) (*PPROF, error) {
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err

1
internal/rtcpsenderset/rtcpsenderset.go

@ -24,7 +24,6 @@ func New( @@ -24,7 +24,6 @@ func New(
tracks gortsplib.Tracks,
onFrame func(int, gortsplib.StreamType, []byte),
) *RTCPSenderSet {
s := &RTCPSenderSet{
onFrame: onFrame,
terminate: make(chan struct{}),

5
internal/rtmpconn/conn.go

@ -95,7 +95,6 @@ func New( @@ -95,7 +95,6 @@ func New(
nconn net.Conn,
pathMan PathMan,
parent Parent) *Conn {
ctx, ctxCancel := context.WithCancel(ctxParent)
c := &Conn{
@ -218,7 +217,8 @@ func (c *Conn) runRead(ctx context.Context) error { @@ -218,7 +217,8 @@ func (c *Conn) runRead(ctx context.Context) error {
ValidateCredentials: func(authMethods []headers.AuthMethod, pathUser string, pathPass string) error {
return c.validateCredentials(pathUser, pathPass, query)
},
Res: sres})
Res: sres,
})
res := <-sres
if res.Err != nil {
@ -527,7 +527,6 @@ func (c *Conn) validateCredentials( @@ -527,7 +527,6 @@ func (c *Conn) validateCredentials(
pathPass string,
query url.Values,
) error {
if query.Get("user") != pathUser ||
query.Get("pass") != pathPass {
return readpublisher.ErrAuthCritical{

1
internal/rtmpserver/server.go

@ -52,7 +52,6 @@ func New( @@ -52,7 +52,6 @@ func New(
stats *stats.Stats,
pathMan *pathman.PathManager,
parent Parent) (*Server, error) {
l, err := net.Listen("tcp", address)
if err != nil {
return nil, err

2
internal/rtmpsource/source.go

@ -53,7 +53,6 @@ func New( @@ -53,7 +53,6 @@ func New(
wg *sync.WaitGroup,
stats *stats.Stats,
parent Parent) *Source {
ctx, ctxCancel := context.WithCancel(ctxParent)
s := &Source{
@ -72,6 +71,7 @@ func New( @@ -72,6 +71,7 @@ func New(
s.wg.Add(1)
go s.run()
return s
}

2
internal/rtspconn/conn.go

@ -70,7 +70,6 @@ func New( @@ -70,7 +70,6 @@ func New(
stats *stats.Stats,
conn *gortsplib.ServerConn,
parent Parent) *Conn {
c := &Conn{
rtspAddress: rtspAddress,
readTimeout: readTimeout,
@ -190,7 +189,6 @@ func (c *Conn) ValidateCredentials( @@ -190,7 +189,6 @@ func (c *Conn) ValidateCredentials(
pathName string,
req *base.Request,
) error {
// reset authValidator every time the credentials change
if c.authValidator == nil || c.authUser != pathUser || c.authPass != pathPass {
c.authUser = pathUser

1
internal/rtspserver/server.go

@ -90,7 +90,6 @@ func New( @@ -90,7 +90,6 @@ func New(
stats *stats.Stats,
pathMan *pathman.PathManager,
parent Parent) (*Server, error) {
ctx, ctxCancel := context.WithCancel(ctxParent)
s := &Server{

1
internal/rtspsession/session.go

@ -58,7 +58,6 @@ func New( @@ -58,7 +58,6 @@ func New(
sc *gortsplib.ServerConn,
pathMan PathMan,
parent Parent) *Session {
s := &Session{
rtspAddress: rtspAddress,
protocols: protocols,

2
internal/rtspsource/source.go

@ -60,7 +60,6 @@ func New( @@ -60,7 +60,6 @@ func New(
wg *sync.WaitGroup,
stats *stats.Stats,
parent Parent) *Source {
ctx, ctxCancel := context.WithCancel(ctxParent)
s := &Source{
@ -83,6 +82,7 @@ func New( @@ -83,6 +82,7 @@ func New(
s.wg.Add(1)
go s.run()
return s
}

3
main.go

@ -112,7 +112,8 @@ func (p *program) Log(level logger.Level, format string, args ...interface{}) { @@ -112,7 +112,8 @@ func (p *program) Log(level logger.Level, format string, args ...interface{}) {
countReaders := atomic.LoadInt64(p.stats.CountReaders)
p.logger.Log(level, "[%d/%d] "+format, append([]interface{}{
countPublishers, countReaders}, args...)...)
countPublishers, countReaders,
}, args...)...)
}
func (p *program) run() {

2
main_rtspreadpub_test.go

@ -863,7 +863,7 @@ wait @@ -863,7 +863,7 @@ wait
require.NoError(t, err)
defer os.Remove(onDemandFile)
err = os.Chmod(onDemandFile, 0755)
err = os.Chmod(onDemandFile, 0o755)
require.NoError(t, err)
t.Run("describe", func(t *testing.T) {

10
main_test.go

@ -60,9 +60,11 @@ func newContainer(image string, name string, args []string) (*container, error) @@ -60,9 +60,11 @@ func newContainer(image string, name string, args []string) (*container, error)
exec.Command("docker", "kill", "rtsp-simple-server-test-"+name).Run()
exec.Command("docker", "wait", "rtsp-simple-server-test-"+name).Run()
cmd := []string{"docker", "run",
cmd := []string{
"docker", "run",
"--name=rtsp-simple-server-test-" + name,
"rtsp-simple-server-test-" + image}
"rtsp-simple-server-test-" + image,
}
cmd = append(cmd, args...)
ecmd := exec.Command(cmd[0], cmd[1:]...)
ecmd.Stdout = nil
@ -189,7 +191,7 @@ func TestHotReloading(t *testing.T) { @@ -189,7 +191,7 @@ func TestHotReloading(t *testing.T) {
" runOnInit: echo aaa\n"+
" test4:\n"+
" runOnInit: echo bbb\n"),
0644)
0o644)
require.NoError(t, err)
defer os.Remove(confPath)
@ -217,7 +219,7 @@ func TestHotReloading(t *testing.T) { @@ -217,7 +219,7 @@ func TestHotReloading(t *testing.T) {
" test3:\n"+
" test4:\n"+
" runOnInit: echo bbb\n"),
0644)
0o644)
require.NoError(t, err)
time.Sleep(1 * time.Second)

Loading…
Cancel
Save