github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/strategy/url_helpers.go (about)

     1  package strategy
     2  
     3  import (
     4  	"net/url"
     5  	"path"
     6  	"strconv"
     7  )
     8  
     9  type params struct {
    10  	resultsPerPage       int64
    11  	orderDirection       string
    12  	q                    map[string]string
    13  	recursive            bool
    14  	inlineRelationsDepth int64
    15  }
    16  
    17  func v2(segments ...string) string {
    18  	segments = append([]string{"/v2"}, segments...)
    19  	return path.Join(segments...)
    20  }
    21  
    22  func buildURL(path string, params params) string {
    23  	query := url.Values{}
    24  
    25  	if params.inlineRelationsDepth != 0 {
    26  		query.Set("inline-relations-depth", strconv.FormatInt(params.inlineRelationsDepth, 10))
    27  	}
    28  
    29  	if params.resultsPerPage != 0 {
    30  		query.Set("results-per-page", strconv.FormatInt(params.resultsPerPage, 10))
    31  	}
    32  
    33  	if params.orderDirection != "" {
    34  		query.Set("order-direction", params.orderDirection)
    35  	}
    36  
    37  	if params.q != nil {
    38  		q := ""
    39  		for key, value := range params.q {
    40  			q += key + ":" + value
    41  		}
    42  		query.Set("q", q)
    43  	}
    44  
    45  	if params.recursive {
    46  		query.Set("recursive", "true")
    47  	}
    48  
    49  	return path + "?" + query.Encode()
    50  }