The net/url package parses URLs, resolves relative references, and encodes query strings. Use url.Parse to convert a string into a structured *url.URL object, then access fields like Scheme, Host, and Path directly.
package main
import (
"fmt"
"net/url"
)
func main() {
u, err := url.Parse("https://example.com/path?query=1")
if err != nil {
panic(err)
}
fmt.Println(u.Scheme, u.Host, u.Path, u.RawQuery)
}