-
Notifications
You must be signed in to change notification settings - Fork 225
pkg/filters: use strings.Cut() #2488
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
Simplify the code a bit. Should not change the behavior. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Reviewer's GuideThe PR refactors filter parsing by replacing manual split logic and a custom helper with Go’s strings.Cut API, streamlining code in PrepareFilters, MatchLabelFilters, and MatchNegatedLabelFilters without altering behavior. Class diagram for refactored filter parsing functionsclassDiagram
class filters {
+PrepareFilters(r *http.Request) map[string][]string
+MatchLabelFilters(filterValues []string, labels map[string]string) bool
+MatchNegatedLabelFilters(filterValues []string, labels map[string]string) bool
-splitFilterValue(filterValue string) (string, string) %% removed
}
filters : -splitFilterValue removed
filters : +PrepareFilters updated to use strings.Cut
filters : +MatchLabelFilters updated to use strings.Cut
filters : +MatchNegatedLabelFilters updated to use strings.Cut
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Luap99, sourcery-ai[bot] The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
LGTM |
mtrmac
left a comment
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
| split := strings.SplitN(filter, "=", 2) | ||
| if len(split) > 1 { | ||
| filterMap[split[0]] = append(filterMap[split[0]], split[1]) | ||
| key, val, found := strings.Cut(filter, "=") |
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.
(FiltersFromRequest just created all of these using %s=%s. We could avoid the single-string form, and the if found condition, entirely, by parsing directly into a map, or at least an array of key-value pairs. And similarly for Podman’s pkg/util/filters.go.
… does this function, as opposed to podman/pkg/util.PrepareFilters, have any callers at all?)
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.
there was a phase were people blindly moved code to c/common for various reasons and then never actually updated podman to use it and remove the podman code...
So yeah that does not surprise me at all and yeah you are right there seems be a lot of pointless conversation involved.
Simplify the code a bit. Should not change the behavior.
Summary by Sourcery
Use strings.Cut to simplify parsing of filter strings across PrepareFilters, MatchLabelFilters, and MatchNegatedLabelFilters while preserving existing behavior.
Enhancements: