mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-10 06:55:21 -04:00
parent
d2cec3776d
commit
a3d7c4a3a9
@ -1,31 +1,33 @@
|
|||||||
---
|
---
|
||||||
title: urls.Parse
|
title: urls.Parse
|
||||||
description: Parse parses a given URL, which may be relative or absolute, into a URL structure.
|
description: Parses a URL into a URL structure.
|
||||||
date: 2017-09-25
|
|
||||||
publishdate: 2017-09-25
|
|
||||||
lastmod: 2017-09-25
|
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: "functions"
|
parent: "functions"
|
||||||
keywords: [urls]
|
keywords: [urls]
|
||||||
signature: ["urls.Parse URL"]
|
signature: ["urls.Parse URL"]
|
||||||
workson: []
|
|
||||||
hugoversion:
|
|
||||||
deprecated: false
|
|
||||||
aliases: []
|
aliases: []
|
||||||
---
|
---
|
||||||
|
|
||||||
`urls.Parse` takes a url as input
|
The `urls.Parse` function parses a URL into a [URL structure](https://godoc.org/net/url#URL). 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.
|
||||||
|
|
||||||
|
[scheme]: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml#uri-schemes-1
|
||||||
|
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $url := urls.Parse "http://www.gohugo.io" }}
|
{{ $url := "https://example.org:123/foo?a=6&b=7#bar" }}
|
||||||
```
|
{{ $u := urls.Parse $url}}
|
||||||
|
|
||||||
and returns a [URL](https://godoc.org/net/url#URL) structure. The struct fields are accessed via the `.` notation:
|
{{ $u.IsAbs }} → true
|
||||||
|
{{ $u.Scheme }} → https
|
||||||
```go-html-template
|
{{ $u.Host }} → example.org:123
|
||||||
{{ $url.Scheme }} → "http"
|
{{ $u.Hostname }} → example.org
|
||||||
{{ $url.Host }} → "www.gohugo.io"
|
{{ $u.RequestURI }} → /foo?a=6&b=7
|
||||||
|
{{ $u.Path }} → /foo
|
||||||
|
{{ $u.Query }} → map[a:[6] b:[7]]
|
||||||
|
{{ $u.Query.a }} → [6]
|
||||||
|
{{ $u.Query.Get "a" }} → 6
|
||||||
|
{{ $u.Query.Has "b" }} → true
|
||||||
|
{{ $u.Fragment }} → bar
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user