pkg/filters: use strings.Cut() - #2488
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
|
|
[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 |
| 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.
(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.
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: