-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.go
More file actions
30 lines (25 loc) · 829 Bytes
/
filter.go
File metadata and controls
30 lines (25 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package jsoner
import (
"slices"
"strings"
)
// newFilter creates a new filter instance, excluding any empty or whitespace-only strings
// from the provided filters.
func newFilter(filters ...string) *filter {
// Remove empty or whitespace-only strings from the filters slice.
cleanedFilters := slices.DeleteFunc(filters, func(item string) bool {
return strings.TrimSpace(item) == ""
})
return &filter{
exclude: cleanedFilters,
}
}
// filter represents a structure that holds a list of fields to exclude.
type filter struct {
exclude []string
}
// shouldSkip checks if a given field should be skipped based on the exclude list.
// It returns true if the field is empty or is present in the exclude list.
func (f *filter) shouldSkip(field string) bool {
return field == "" || slices.Contains(f.exclude, field)
}