URL parsing
Context
Section titled “Context”The net/url package parses URLs and escapes query strings. Use url.Parse to break a URL into components.
Example
Section titled “Example”Parse a URL and extract parts.
Code example
Section titled “Code example”package main
import ( "fmt" "net/url")
func main() { s := "https://example.com:8080/path?name=Alice&age=30#section" u, err := url.Parse(s) if err != nil { panic(err) } fmt.Println("Scheme:", u.Scheme) fmt.Println("Host:", u.Host) fmt.Println("Path:", u.Path) fmt.Println("Query:", u.Query()) fmt.Println("Fragment:", u.Fragment)}Output
Section titled “Output”Scheme: httpsHost: example.com:8080Path: /pathQuery: map[age:[30] name:[Alice]]Fragment: section