-
Notifications
You must be signed in to change notification settings - Fork 262
Use slices
and maps
more where appropriate
#2306
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kolyshkin, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cmd/containers-storage/main.go
Outdated
@@ -84,63 +85,61 @@ func main() { | |||
cmd := args[0] | |||
|
|||
for _, command := range commands { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: This works, and it is an improvement already, but processing commands
in a loop is not quite what we mean.
Consider
i := slices.IndexFunc(commands, func(c) { slices.Contains(c.names, cmd) })
if i == -1 { /* fail */ }
command := commands[i]
// straight-line top-level code processing the command we found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, this looks weird.
Rewrote (I left for range
as it seems more readable than slices.IndexFunc
in this particular case).
...by using maps.Clone if possible. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Simplify the code that finds the command. While at it, rename cmd to name to avoid using cmd and command together. Best reviewed with --ignore-all-space. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
fmt.Printf("%s: unrecognized command.\n", name) | ||
os.Exit(1) | ||
return nil // To satisfy linters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Absolutely non-blocking: Aesthetically, I’d prefer return nil
here, and having os.Exit
at the top level, but this works perfectly fine.)
/lgtm |
Please see individual commits for details.