Add filters to listing different resources in the go sdk. (#957)

This commit is contained in:
Todd Knight authored and GitHub committed 2021-02-22 13:31:17 -07:00
1 parent 2ed1643e3a
commit cac1e60e11
13 files changed
+185 -1

No files matched your search

+15
View File
@@ -1,6 +1,8 @@
package hostsets
import (
"strings"
"github.com/hashicorp/boundary/api"
)
@@ -18,6 +20,7 @@ type options struct {
queryMap map[string]string
withAutomaticVersioning bool
withSkipCurlOutput bool
withFilter string
}
func getDefaultOptions() options {
@@ -36,6 +39,9 @@ func getOpts(opt ...Option) (options, []api.Option) {
if opts.withSkipCurlOutput {
apiOpts = append(apiOpts, api.WithSkipCurlOutput(true))
}
if opts.withFilter != "" {
opts.queryMap["filter"] = opts.withFilter
}
return opts, apiOpts
}
@@ -57,6 +63,15 @@ func WithSkipCurlOutput(skip bool) Option {
}
}
// WithFilter tells the API to filter the items returned using the provided
// filter term. The filter should be in a format supported by
// hashicorp/go-bexpr.
func WithFilter(filter string) Option {
return func(o *options) {
o.withFilter = strings.TrimSpace(filter)
}
}
func WithDescription(inDescription string) Option {
return func(o *options) {
o.postMap["description"] = inDescription