Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(38)

Side by Side Diff: src/pkg/http/url.go

Issue 2985042: code review 2985042: http: Add EncodeQuery, a handy helper function for cons... (Closed)
Patch Set: code review 2985042: http: Add EncodeQuery, a handy helper function for cons... Created 14 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/http/client.go ('k') | src/pkg/http/url_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 "os" 12 "os"
12 "strconv" 13 "strconv"
13 "strings" 14 "strings"
14 ) 15 )
15 16
16 // URLError reports an error and the operation and URL that caused it. 17 // URLError reports an error and the operation and URL that caused it.
17 type URLError struct { 18 type URLError struct {
18 Op string 19 Op string
19 URL string 20 URL string
20 Error os.Error 21 Error os.Error
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 result += urlEscape(url.Path, encodePath) 509 result += urlEscape(url.Path, encodePath)
509 } 510 }
510 if url.RawQuery != "" { 511 if url.RawQuery != "" {
511 result += "?" + url.RawQuery 512 result += "?" + url.RawQuery
512 } 513 }
513 if url.Fragment != "" { 514 if url.Fragment != "" {
514 result += "#" + urlEscape(url.Fragment, encodeFragment) 515 result += "#" + urlEscape(url.Fragment, encodeFragment)
515 } 516 }
516 return result 517 return result
517 } 518 }
519
520 // EncodeQuery encodes the query represented as a multimap.
521 // Each key's value is encoded as a string using fmt.Sprint, then URL-encoded.
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
524 for k, vs := range m {
525 prefix := URLEscape(k) + "="
526 for _, v := range vs {
527 parts = append(parts, prefix+URLEscape(fmt.Sprint(v)))
528 }
529 }
530 return strings.Join(parts, "&")
531 }
OLDNEW
« no previous file with comments | « src/pkg/http/client.go ('k') | src/pkg/http/url_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b