| 1 |
--- |
| 2 |
title: urls.Parse |
| 3 |
description: Returns a URL structure parsed from the given URL. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: url.URL |
| 10 |
signatures: [urls.Parse URL] |
| 11 |
aliases: [/functions/urls.parse] |
| 12 |
--- |
| 13 |
|
| 14 |
The `urls.Parse` function parses a URL into a [URL structure][]. The URL may be relative (a path, without a host) or absolute (starting with a [scheme][]). Hugo throws an error when parsing an invalid URL. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ $url := "https://example.org:123/foo?a=6&b=7#bar" }} |
| 18 |
{{ $u := urls.Parse $url }} |
| 19 |
|
| 20 |
{{ $u.String }} → https://example.org:123/foo?a=6&b=7#bar |
| 21 |
{{ $u.IsAbs }} → true |
| 22 |
{{ $u.Scheme }} → https |
| 23 |
{{ $u.Host }} → example.org:123 |
| 24 |
{{ $u.Hostname }} → example.org |
| 25 |
{{ $u.RequestURI }} → /foo?a=6&b=7 |
| 26 |
{{ $u.Path }} → /foo |
| 27 |
{{ $u.RawQuery }} → a=6&b=7 |
| 28 |
{{ $u.Query }} → map[a:[6] b:[7]] |
| 29 |
{{ $u.Query.a }} → [6] |
| 30 |
{{ $u.Query.Get "a" }} → 6 |
| 31 |
{{ $u.Query.Has "b" }} → true |
| 32 |
{{ $u.Fragment }} → bar |
| 33 |
``` |
| 34 |
|
| 35 |
[URL structure]: https://godoc.org/net/url#URL |
| 36 |
[scheme]: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml#uri-schemes-1 |