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

+14 -1
View File
@@ -657,6 +657,7 @@ type options struct {
queryMap map[string]string
withAutomaticVersioning bool
withSkipCurlOutput bool
withFilter string
{{ if .RecursiveListing }} withRecursive bool {{ end }}
}
@@ -675,7 +676,10 @@ func getOpts(opt ...Option) (options, []api.Option) {
var apiOpts []api.Option
if opts.withSkipCurlOutput {
apiOpts = append(apiOpts, api.WithSkipCurlOutput(true))
} {{ if .RecursiveListing }}
}
if opts.withFilter != "" {
opts.queryMap["filter"] = opts.withFilter
}{{ if .RecursiveListing }}
if opts.withRecursive {
opts.queryMap["recursive"] = strconv.FormatBool(opts.withRecursive)
} {{ end }}
@@ -699,6 +703,15 @@ func WithSkipCurlOutput(skip bool) Option {
o.withSkipCurlOutput = true
}
}
// 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)
}
}
{{ if .RecursiveListing }}
// WithRecursive tells the API to use recursion for listing operations on this
// resource