Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add golangci-lint #48

Merged
merged 1 commit into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/golangci-lint.yml
@@ -0,0 +1,26 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@07db5389c99593f11ad7b44463c2d4233066a9b1
with:
version: v1.50
args: --timeout=3m
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
.DS_Store
.idea/
.vscode/
.golangci.yml

vendor/
bin/
26 changes: 14 additions & 12 deletions main.go
Expand Up @@ -28,16 +28,17 @@ var (

func main() {
flag.Parse()
log.Println("Pinging Docker...")

cli, err := client.NewClientWithOpts()
if err == nil {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

_, err = cli.Ping(ctx)
if err != nil {
panic(err)
}

pingCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

log.Println("Pinging Docker...")
_, err = cli.Ping(pingCtx)
if err != nil {
panic(err)
}
Expand All @@ -62,11 +63,12 @@ func main() {

func processRequests(deathNote *sync.Map, connectionAccepted chan<- net.Addr, connectionLost chan<- net.Addr) {
log.Printf("Starting on port %d...", *port)
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))

ln, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
panic(err)
}

log.Println("Started!")
for {
conn, err := ln.Accept()
Expand Down Expand Up @@ -112,7 +114,7 @@ func processRequests(deathNote *sync.Map, connectionAccepted chan<- net.Addr, co

deathNote.Store(param, true)

conn.Write([]byte("ACK\n"))
_, _ = conn.Write([]byte("ACK\n"))
}

if err != nil {
Expand Down Expand Up @@ -190,12 +192,12 @@ func prune(cli *client.Client, deathNote *sync.Map) (deletedContainers int, dele
log.Println(err)
} else {
for _, container := range containers {
cli.ContainerRemove(context.Background(), container.ID, types.ContainerRemoveOptions{RemoveVolumes: true, Force: true})
_ = cli.ContainerRemove(context.Background(), container.ID, types.ContainerRemoveOptions{RemoveVolumes: true, Force: true})
deletedContainersMap[container.ID] = true
}
}

try.Do(func(attempt int) (bool, error) {
_ = try.Do(func(attempt int) (bool, error) {
networksPruneReport, err := cli.NetworksPrune(context.Background(), args)
for _, networkID := range networksPruneReport.NetworksDeleted {
deletedNetworksMap[networkID] = true
Expand All @@ -208,7 +210,7 @@ func prune(cli *client.Client, deathNote *sync.Map) (deletedContainers int, dele
return shouldRetry, err
})

try.Do(func(attempt int) (bool, error) {
_ = try.Do(func(attempt int) (bool, error) {
volumesPruneReport, err := cli.VolumesPrune(context.Background(), args)
for _, volumeName := range volumesPruneReport.VolumesDeleted {
deletedVolumesMap[volumeName] = true
Expand All @@ -221,7 +223,7 @@ func prune(cli *client.Client, deathNote *sync.Map) (deletedContainers int, dele
return shouldRetry, err
})

try.Do(func(attempt int) (bool, error) {
_ = try.Do(func(attempt int) (bool, error) {
args.Add("dangling", "false")
imagesPruneReport, err := cli.ImagesPrune(context.Background(), args)
for _, image := range imagesPruneReport.ImagesDeleted {
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestPrune(t *testing.T) {
require.Nil(t, err)
require.NotNil(t, network)
t.Cleanup(func() {
network.Remove(ctx)
_ = network.Remove(ctx)
})
}

Expand Down Expand Up @@ -201,7 +201,7 @@ func TestPrune(t *testing.T) {
require.Nil(t, err)
require.NotNil(t, vol)
t.Cleanup(func() {
cli.VolumeRemove(ctx, vol.Name, true)
_ = cli.VolumeRemove(ctx, vol.Name, true)
})
}

Expand All @@ -227,7 +227,7 @@ func TestPrune(t *testing.T) {
dockerFileReader, err := os.Open(filepath.Join("testresources", dockerFile))
require.Nil(t, err)

readDockerFile, err := ioutil.ReadAll(dockerFileReader)
readDockerFile, err := io.ReadAll(dockerFileReader)
require.Nil(t, err)

tarHeader := &tar.Header{
Expand Down