u, err := url.Parse("http://example.com/path?foo=bar&baz=qux") if err != nil { log.Fatal(err) } query := u.Query() foo := query.Get("foo") // "bar" baz := query.Get("baz") // "qux"
u, err := url.Parse("http://example.com/path") if err != nil { log.Fatal(err) } query := u.Query() query.Set("foo", "bar") u.RawQuery = query.Encode() // u.String() now returns "http://example.com/path?foo=bar"
u, err := url.Parse("http://example.com/path?foo=bar&baz=qux") if err != nil { log.Fatal(err) } query := u.Query() query.Del("foo") u.RawQuery = query.Encode() // u.String() now returns "http://example.com/path?baz=qux"This code removes the "foo" query parameter from the URL "http://example.com/path?foo=bar&baz=qux". In conclusion, the "net/url" package in Go is a powerful tool for working with URLs, and specifically for manipulating query parameters.