-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilter.go
More file actions
34 lines (27 loc) · 699 Bytes
/
filter.go
File metadata and controls
34 lines (27 loc) · 699 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
31
32
33
34
package apicalypse
import (
"github.com/pkg/errors"
"strings"
)
// newFilters returns a filter map mutated by the provided Option arguments.
// If no Option's are provided, an empty map is returned.
func newFilters(funcOpts ...Option) (map[string]string, error) {
filters := map[string]string{}
for _, f := range funcOpts {
if err := f(filters); err != nil {
return nil, errors.Wrap(err, "cannot create new options")
}
}
return filters, nil
}
// toString returns the filters as a single string.
func toString(f map[string]string) string {
if len(f) <= 0 {
return ""
}
b := strings.Builder{}
for k, v := range f {
b.WriteString(k + " " + v + "; ")
}
return b.String()
}