MCPcopy Index your code
hub / github.com/apache/cloudstack-go / EncodeValues

Function EncodeValues

cloudstack/cloudstack.go:608–635  ·  view source on GitHub ↗

Custom version of net/url Encode that only URL escapes values Unmodified portions here remain under BSD license of The Go Authors: https://go.googlesource.com/go/+/master/LICENSE

(v url.Values)

Source from the content-addressed store, hash-verified

606// Custom version of net/url Encode that only URL escapes values
607// Unmodified portions here remain under BSD license of The Go Authors: https://go.googlesource.com/go/+/master/LICENSE
608func EncodeValues(v url.Values) string {
609 if v == nil {
610 return ""
611 }
612 var buf bytes.Buffer
613 keys := make([]string, 0, len(v))
614 for k := range v {
615 keys = append(keys, k)
616 }
617 sort.Strings(keys)
618 for _, k := range keys {
619 vs := v[k]
620 prefix := k + "="
621 for _, v := range vs {
622 if buf.Len() > 0 {
623 buf.WriteByte('&')
624 }
625 buf.WriteString(prefix)
626 escaped := url.QueryEscape(v)
627 // we need to ensure + (representing a space) is encoded as %20
628 escaped = strings.Replace(escaped, "+", "%20", -1)
629 // we need to ensure * is not escaped
630 escaped = strings.Replace(escaped, "%2A", "*", -1)
631 buf.WriteString(escaped)
632 }
633 }
634 return buf.String()
635}
636
637// Generic function to get the first non-count raw value from a response as json.RawMessage
638func getRawValue(b json.RawMessage) (json.RawMessage, error) {

Callers 2

TestEncodeValuesFunction · 0.92
newRawRequestMethod · 0.85

Calls 1

LenMethod · 0.45

Tested by 1

TestEncodeValuesFunction · 0.74