github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv2/query.go (about) 1 package ccv2 2 3 import ( 4 "fmt" 5 "net/url" 6 ) 7 8 // QueryFilter is the type of filter a Query uses. 9 type QueryFilter string 10 11 // QueryOperator is the type of operation a Query uses. 12 type QueryOperator string 13 14 const ( 15 // AppGUIDFilter is the name of the App GUID filter. 16 AppGUIDFilter QueryFilter = "app_guid" 17 // OrganizationGUIDFilter is the name of the organization GUID filter. 18 OrganizationGUIDFilter QueryFilter = "organization_guid" 19 // RouteGUIDFilter is the name of the route GUID filter. 20 RouteGUIDFilter QueryFilter = "route_guid" 21 // ServiceInstanceGUIDFilter is the name of the service instance GUID filter. 22 ServiceInstanceGUIDFilter QueryFilter = "service_instance_guid" 23 // SpaceGUIDFilter is the name of the space GUID filter. 24 SpaceGUIDFilter QueryFilter = "space_guid" 25 26 // NameFilter is the name of the name filter. 27 NameFilter QueryFilter = "name" 28 ) 29 30 const ( 31 // EqualOperator is the query equal operator. 32 EqualOperator QueryOperator = ":" 33 ) 34 35 // Query is a type of filter that can be passed to specific request to narrow 36 // down the return set. 37 type Query struct { 38 Filter QueryFilter 39 Operator QueryOperator 40 Value string 41 } 42 43 func (query Query) format() string { 44 return fmt.Sprintf("%s%s%s", query.Filter, query.Operator, query.Value) 45 } 46 47 // FormatQueryParameters converts a Query object into a collection that 48 // cloudcontroller.Request can accept. 49 func FormatQueryParameters(queries []Query) url.Values { 50 params := url.Values{"q": []string{}} 51 for _, query := range queries { 52 params["q"] = append(params["q"], query.format()) 53 } 54 55 return params 56 }