github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/net/url/example_test.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package url_test 6 7 import ( 8 "fmt" 9 "log" 10 "net/url" 11 ) 12 13 func ExampleValues() { 14 v := url.Values{} 15 v.Set("name", "Ava") 16 v.Add("friend", "Jess") 17 v.Add("friend", "Sarah") 18 v.Add("friend", "Zoe") 19 // v.Encode() == "name=Ava&friend=Jess&friend=Sarah&friend=Zoe" 20 fmt.Println(v.Get("name")) 21 fmt.Println(v.Get("friend")) 22 fmt.Println(v["friend"]) 23 // Output: 24 // Ava 25 // Jess 26 // [Jess Sarah Zoe] 27 } 28 29 func ExampleURL() { 30 u, err := url.Parse("http://bing.com/search?q=dotnet") 31 if err != nil { 32 log.Fatal(err) 33 } 34 u.Scheme = "https" 35 u.Host = "google.com" 36 q := u.Query() 37 q.Set("q", "golang") 38 u.RawQuery = q.Encode() 39 fmt.Println(u) 40 // Output: https://google.com/search?q=golang 41 }