Skip to content

Commit 3c05650

Browse files
MrMohebitaraspos
andauthored
Convert slice.Contains to swtich case
Co-authored-by: Taras <[email protected]>
1 parent f8532c1 commit 3c05650

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

cli/docker_handler.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,28 @@ func (c *DockerHandler) watch() {
104104
}
105105
}()
106106

107-
lifecycleEvents := []string{
108-
"create",
109-
"start",
110-
"restart",
111-
"stop",
112-
"kill",
113-
"die",
114-
"destroy",
115-
}
116107

117-
otherManagementEvents := []string{
118-
"pause",
119-
"unpause",
120-
"rename",
121-
"update",
122-
}
108+
shouldProcessEvent := func(event *docker.APIEvents) bool {
109+
if event.Type != "container":
110+
return false
111+
}
112+
113+
switch (event.Action) {
114+
// lifecycle events
115+
case "create", "start", "restart", "stop", "kill", "die", "destroy":
116+
return true
117+
// other management events
118+
case "pause", "unpause", "rename", "update":
119+
return true
120+
default:
121+
return false
122+
}
123+
}
123124

124125
for event := range events {
125-
if event.Type == "container" && (slices.Contains(lifecycleEvents, event.Action) || slices.Contains(otherManagementEvents, event.Action)) {
126+
if !shouldProcessEvent(event) {
127+
continue
128+
}
126129
labels, err := c.GetDockerLabels()
127130
// Do not print or care if there is no container up right now
128131
if err != nil && !errors.Is(err, errNoContainersMatchingFilters) {

0 commit comments

Comments
 (0)