import ( "net/url" "fmt" ) func main() { u, err := url.Parse("http://example.com/path?foo=bar&baz=qux") if err != nil { panic(err) } v := u.Query() // Get query string values as a map[string][]string fmt.Println(v.Get("foo")) // Output: bar // Convert map[string][]string to url.Values values := url.Values{} for k, vs := range v { for _, v := range vs { values.Add(k, v) } } }
import ( "net/url" "fmt" ) func main() { values := url.Values{} values.Set("foo", "bar") values.Add("baz", "qux") u := &url.URL{ Scheme: "http", Host: "example.com", Path: "/path", RawQuery: values.Encode(), } fmt.Println(u.String()) // Output: http://example.com/path?foo=bar&baz=qux }This example creates a `url.Values` object with two parameters and builds a URL with those parameters using the `Encode()` function. Package library: net/url