Standard library / net/url
url.Parse()
Parse a URL reference; a missing scheme is permitted. Validate scheme and host separately. Expected stdout: 'https example.invalid /a\n'.
Formal Syntax & Structure
go syntaxgo
func Parse(rawURL string) (*URL, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| rawURL | string | URL string to parse. |
Return Value
(*URL, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/url")
func main() { u := must(url.Parse("https://example.invalid/a")); fmt.Println(u.Scheme, u.Host, u.Path) }
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}