// create a new empty set of values values := url.Values{} // set the 'q' query parameter to 'golang' values.Set("q", "golang") // add another query parameter values.Set("sort", "relevance")
// parse a URL string parsedUrl, _ := url.Parse("https://www.example.com/search?q=golang") // get the existing query parameters values := parsedUrl.Query() // set the 'q' query parameter to 'golang rocks' values.Set("q", "golang rocks") // update the query parameters in the URL parsedUrl.RawQuery = values.Encode()This example demonstrates how to parse a URL string using the Parse function provided by the url package. We then call the Query function on the parsed URL to get the existing query parameters as a set of Values. We use the Set function to change the value of the 'q' query parameter, and then update the query parameters in the URL using the Encode function provided by the Values type. Overall, these examples demonstrate how to use the Set function provided by the Values type in the net/url package to manipulate query parameters in URLs.