github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/api/cloudcontroller/ccv2/filter.go (about) 1 package ccv2 2 3 import ( 4 "fmt" 5 "net/url" 6 "strings" 7 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 9 ) 10 11 // Filter is a type of filter that can be passed to specific request to narrow 12 // down the return set. 13 type Filter struct { 14 // Type is the component that determines what the query is filtered by. 15 Type constant.FilterType 16 17 // Operator is the component that determines how the the query will be filtered. 18 Operator constant.FilterOperator 19 20 // Values is the component that determines what values are filtered. 21 Values []string 22 } 23 24 func (filter Filter) format() string { 25 return fmt.Sprintf("%s%s%s", filter.Type, filter.Operator, strings.Join(filter.Values, ",")) 26 } 27 28 // ConvertFilterParameters converts a Filter object into a collection that 29 // cloudcontroller.Request can accept. 30 func ConvertFilterParameters(filters []Filter) url.Values { 31 params := url.Values{"q": []string{}} 32 for _, filter := range filters { 33 params["q"] = append(params["q"], filter.format()) 34 } 35 36 return params 37 }