| 1 |
--- |
| 2 |
title: Data |
| 3 |
description: Applicable to resources returned by the resources.GetRemote function, returns information from the HTTP response. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: map |
| 9 |
signatures: [RESOURCE.Data] |
| 10 |
--- |
| 11 |
|
| 12 |
The `Data` method on a resource returned by the [`resources.GetRemote`][] function returns information from the HTTP response. |
| 13 |
|
| 14 |
## Example |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ $url := "https://example.org/images/a.jpg" }} |
| 18 |
{{ $opts := dict "responseHeaders" (slice "Server") }} |
| 19 |
{{ with try (resources.GetRemote $url) }} |
| 20 |
{{ with .Err }} |
| 21 |
{{ errorf "%s" . }} |
| 22 |
{{ else with .Value }} |
| 23 |
{{ with .Data }} |
| 24 |
{{ .ContentLength }} → 42764 |
| 25 |
{{ .ContentType }} → image/jpeg |
| 26 |
{{ .Headers }} → map[Server:[Netlify]] |
| 27 |
{{ .Status }} → 200 OK |
| 28 |
{{ .StatusCode }} → 200 |
| 29 |
{{ .TransferEncoding }} → [] |
| 30 |
{{ end }} |
| 31 |
{{ else }} |
| 32 |
{{ errorf "Unable to get remote resource %q" $url }} |
| 33 |
{{ end }} |
| 34 |
{{ end }} |
| 35 |
``` |
| 36 |
|
| 37 |
## Methods |
| 38 |
|
| 39 |
Use these methods on the `Data` object. |
| 40 |
|
| 41 |
`ContentLength` |
| 42 |
: (`int`) The content length in bytes. |
| 43 |
|
| 44 |
`ContentType` |
| 45 |
: (`string`) The content type. |
| 46 |
|
| 47 |
`Headers` |
| 48 |
: (`map[string][]string`) A map of response headers matching those requested in the [`responseHeaders`][] option passed to the `resources.GetRemote` function. The header name matching is case-insensitive. In most cases there will be one value per header key. |
| 49 |
|
| 50 |
`Status` |
| 51 |
: (`string`) The HTTP status text. |
| 52 |
|
| 53 |
`StatusCode` |
| 54 |
: (`int`) The HTTP status code. |
| 55 |
|
| 56 |
`TransferEncoding` |
| 57 |
: (`string`) The transfer encoding. |
| 58 |
|
| 59 |
[`resources.GetRemote`]: /functions/resources/getremote/ |
| 60 |
[`responseHeaders`]: /functions/resources/getremote/#responseheaders |