Introduction
The purpose of this challenge is to demonstrate how to parse URLs in Go.
The purpose of this challenge is to demonstrate how to parse URLs in Go.
The challenge requires parsing a sample URL that includes a scheme, authentication info, host, port, path, query params, and query fragment. The parsed URL should be used to extract the individual components of the URL.
url
and net
packages should be imported.SplitHostPort
function should be used to extract the hostname and port from the Host
field.ParseQuery
function should be used to parse the query params into a map.## Running our URL parsing program shows all the different
## pieces that we extracted.
$ go run url-parsing.go
postgres
user:pass
user
pass
host.com:5432
host.com
5432
/path
f
k=v
map[k:[v]]
v
The URL Parsing requires parsing a sample URL and extracting the individual components of the URL. The url
and net
packages are used to parse and extract the URL components.