Complete Guide to the net/url Package in Go

Web
The net/url package parses, resolves, and encodes URLs in Go, providing structured access to scheme, host, and path components.

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)
}