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)
| 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 |
| 608 | func 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 |
| 638 | func getRawValue(b json.RawMessage) (json.RawMessage, error) { |