func handleRequest(w http.ResponseWriter, r *http.Request) { uri := r.RequestURI fmt.Fprintf(w, "URI: %s", uri) } http.HandleFunc("/", handleRequest) http.ListenAndServe(":8080", nil)
func handleRequest(w http.ResponseWriter, r *http.Request) { newURI := "https://example.com" + r.RequestURI http.Redirect(w, r, newURI, http.StatusMovedPermanently) } http.HandleFunc("/", handleRequest) http.ListenAndServe(":8080", nil)In this example, we create an HTTP server that redirects all requests to a new URI by appending the request URI to the new URI. We obtain the request URI using the `RequestURI` field of the `Request` struct. Package library: `net/http`