Skip to content

Commit b0a5aee

Browse files
arnesteddependabot[bot]
authored andcommitted
Fix golangci-lint issues
1 parent f036880 commit b0a5aee

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
linters:
22
enable-all: true
3-
3+
disable:
4+
- depguard
5+
- exhaustruct

containers.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ type Container struct {
1717
type Containers map[string]Container
1818

1919
// Add a container to the list of monitored containers.
20-
func (c *Containers) Add(id string, new Container) {
20+
func (c *Containers) Add(containerID string, newContainer Container) {
2121
// Is container already in containers?
22-
existing, ok := (*c)[id]
22+
existing, ok := (*c)[containerID]
2323

2424
if !ok {
25-
(*c)[id] = new
25+
(*c)[containerID] = newContainer
2626

2727
return
2828
}
2929

3030
// This is an old state (we know a newer state). Ignore and
3131
// return.
32-
if existing.Changed.After(new.Changed) {
32+
if existing.Changed.After(newContainer.Changed) {
3333
return
3434
}
3535

3636
// Remember the new state.
37-
(*c)[id] = new
37+
(*c)[containerID] = newContainer
3838
}
3939

4040
// Healthy if all containers are healthy.
41-
func (c Containers) Healthy() bool {
42-
for _, container := range c {
41+
func (c *Containers) Healthy() bool {
42+
for _, container := range *c {
4343
if container.Status != types.Healthy && container.Status != types.NoHealthcheck {
4444
return false
4545
}
@@ -49,12 +49,12 @@ func (c Containers) Healthy() bool {
4949
}
5050

5151
// Unhealthy if one of the containers get unhealthy.
52-
func (c Containers) Unhealthy() error {
53-
for _, container := range c {
52+
func (c *Containers) Unhealthy() error {
53+
for _, container := range *c {
5454
if container.Status == types.Unhealthy {
5555
return fmt.Errorf(
5656
"%w: %s",
57-
unhealthyError,
57+
errUnhealthy,
5858
strings.Join(c.UnhealtyContainers(), ", "),
5959
)
6060
}
@@ -64,10 +64,10 @@ func (c Containers) Unhealthy() error {
6464
}
6565

6666
// NonHealtyContainers returns a list of container names of containers that are not healthy (yet).
67-
func (c Containers) NonHealtyContainers() []string {
67+
func (c *Containers) NonHealtyContainers() []string {
6868
var nonHealthy []string
6969

70-
for _, container := range c {
70+
for _, container := range *c {
7171
if container.Status != types.Healthy && container.Status != types.NoHealthcheck {
7272
nonHealthy = append(nonHealthy, container.Name)
7373
}
@@ -77,10 +77,10 @@ func (c Containers) NonHealtyContainers() []string {
7777
}
7878

7979
// UnhealtyContainers returns a list of container names of containers that are not healthy (yet).
80-
func (c Containers) UnhealtyContainers() []string {
80+
func (c *Containers) UnhealtyContainers() []string {
8181
var unhealthy []string
8282

83-
for _, container := range c {
83+
for _, container := range *c {
8484
if container.Status == types.Unhealthy {
8585
unhealthy = append(unhealthy, container.Name)
8686
}

event.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ func (e Error) Error() string {
1919
}
2020

2121
const (
22-
timeoutError Error = "timeout while waiting for containers to be healthy"
23-
unhealthyError Error = "containers are unhealthy"
22+
errTimeout Error = "timeout while waiting for containers to be healthy"
23+
errUnhealthy Error = "containers are unhealthy"
2424
)
2525

26-
func listen(c Containers, since time.Time, timeout time.Duration, failOnUnhealthy bool) (bool, error) {
26+
func listen(containers Containers, since time.Time, timeout time.Duration, failOnUnhealthy bool) (bool, error) {
2727
cli, err := client.NewClientWithOpts(
2828
client.FromEnv,
2929
client.WithAPIVersionNegotiation(),
3030
)
3131
if err != nil {
32-
return false, err
32+
return false, fmt.Errorf("creating Docker client: %w", err)
3333
}
3434

3535
filter := filters.NewArgs()
3636
filter.Add("type", "container")
3737
filter.Add("event", "health_status")
3838

39-
for id := range c {
39+
for id := range containers {
4040
filter.Add("container", id)
4141
}
4242

@@ -60,21 +60,21 @@ func listen(c Containers, since time.Time, timeout time.Duration, failOnUnhealth
6060
Changed: time.Unix(msg.Time, msg.TimeNano),
6161
}
6262

63-
c.Add(msg.ID, container)
63+
containers.Add(msg.ID, container)
6464

65-
if c.Healthy() {
65+
if containers.Healthy() {
6666
return true, nil
6767
}
6868

69-
if err := c.Unhealthy(); err != nil && failOnUnhealthy {
69+
if err := containers.Unhealthy(); err != nil && failOnUnhealthy {
7070
return false, err
7171
}
7272
case <-timeoutChan:
7373
return false, fmt.Errorf(
7474
"%w (%s): %s",
75-
timeoutError,
75+
errTimeout,
7676
timeout,
77-
strings.Join(c.NonHealtyContainers(), ", "),
77+
strings.Join(containers.NonHealtyContainers(), ", "),
7878
)
7979
}
8080
}

main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,34 @@ func main() {
3333
fail(err)
3434
}
3535

36-
c := Containers{}
36+
containers := Containers{}
3737

3838
for _, container := range flag.Args() {
3939
ID, container, err := containerInfo(container, cli, since)
4040
if err != nil {
4141
fail(err)
4242
}
4343

44-
c.Add(ID, *container)
44+
containers.Add(ID, *container)
4545
}
4646

47-
if c.Healthy() {
47+
if containers.Healthy() {
4848
os.Exit(0)
4949
}
5050

51-
if err := c.Unhealthy(); err != nil && *failOnUnhealthy {
51+
if err := containers.Unhealthy(); err != nil && *failOnUnhealthy {
5252
fail(err)
5353
}
5454

55-
if _, err := listen(c, since, *timeout, *failOnUnhealthy); err != nil {
55+
if _, err := listen(containers, since, *timeout, *failOnUnhealthy); err != nil {
5656
fail(err)
5757
}
5858
}
5959

6060
func containerInfo(containerID string, cli *client.Client, since time.Time) (string, *Container, error) {
6161
info, err := cli.ContainerInspect(context.Background(), containerID)
6262
if err != nil {
63-
return "", nil, err
63+
return "", nil, fmt.Errorf("inspecting container: %w", err)
6464
}
6565

6666
state := types.NoHealthcheck
@@ -69,13 +69,13 @@ func containerInfo(containerID string, cli *client.Client, since time.Time) (str
6969
state = info.State.Health.Status
7070
}
7171

72-
c := &Container{
72+
container := &Container{
7373
Status: state,
7474
Changed: since,
7575
Name: strings.TrimLeft(info.Name, "/"),
7676
}
7777

78-
return info.ID, c, nil
78+
return info.ID, container, nil
7979
}
8080

8181
func fail(err error) {

0 commit comments

Comments
 (0)