Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Parse URLs (actually URIs, but that seems overly pedantic). | 5 // Parse URLs (actually URIs, but that seems overly pedantic). |
6 // RFC 3986 | 6 // RFC 3986 |
7 | 7 |
8 package http | 8 package http |
9 | 9 |
10 import ( | 10 import ( |
11 "fmt" | |
12 "os" | 11 "os" |
13 "strconv" | 12 "strconv" |
14 "strings" | 13 "strings" |
15 ) | 14 ) |
16 | 15 |
17 // URLError reports an error and the operation and URL that caused it. | 16 // URLError reports an error and the operation and URL that caused it. |
18 type URLError struct { | 17 type URLError struct { |
19 Op string | 18 Op string |
20 URL string | 19 URL string |
21 Error os.Error | 20 Error os.Error |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 if url.RawQuery != "" { | 510 if url.RawQuery != "" { |
512 result += "?" + url.RawQuery | 511 result += "?" + url.RawQuery |
513 } | 512 } |
514 if url.Fragment != "" { | 513 if url.Fragment != "" { |
515 result += "#" + urlEscape(url.Fragment, encodeFragment) | 514 result += "#" + urlEscape(url.Fragment, encodeFragment) |
516 } | 515 } |
517 return result | 516 return result |
518 } | 517 } |
519 | 518 |
520 // EncodeQuery encodes the query represented as a multimap. | 519 // EncodeQuery encodes the query represented as a multimap. |
521 // Each key's value is encoded as a string using fmt.Sprint, then URL-encoded. | 520 func EncodeQuery(m map[string][]string) string { |
522 func EncodeQuery(m map[string][]interface{}) string { | |
rsc
2010/11/24 01:22:38
I'm not okay with this. Why interface{}? What va
dsymonds
2010/11/24 01:54:03
It's interface{} in the same way that fmt.Print, e
| |
523 parts := make([]string, 0, len(m)) // will be large enough for most uses | 521 parts := make([]string, 0, len(m)) // will be large enough for most uses |
524 for k, vs := range m { | 522 for k, vs := range m { |
525 prefix := URLEscape(k) + "=" | 523 prefix := URLEscape(k) + "=" |
526 for _, v := range vs { | 524 for _, v := range vs { |
527 » » » parts = append(parts, prefix+URLEscape(fmt.Sprint(v))) | 525 » » » parts = append(parts, prefix+URLEscape(v)) |
528 } | 526 } |
529 } | 527 } |
530 return strings.Join(parts, "&") | 528 return strings.Join(parts, "&") |
531 } | 529 } |
LEFT | RIGHT |