package main import ( "fmt" "net/url" ) func main() { urlString := "https://www.google.com/search?q=golang" parsedURL, _ := url.Parse(urlString) // Get the hostname of the URL fmt.Println(parsedURL.Host) // Output: "www.google.com" // Set a new hostname for the URL parsedURL.Host = "www.example.com" fmt.Println(parsedURL.String()) // Output: "https://www.example.com/search?q=golang" }In the above example, we create a URL by parsing a string using the url.Parse function. We then use the Host field to get the hostname of the URL and set a new hostname for the URL. The output of the program shows the original hostname and the updated URL with the new hostname. The package library for this example is net/url.