| 1 |
--- |
| 2 |
title: Data |
| 3 |
description: Returns supplemental information about resources produced by the resources.GetRemote, css.Build, and js.Build functions. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: map |
| 9 |
signatures: [RESOURCE.Data] |
| 10 |
--- |
| 11 |
|
| 12 |
The `Data` method returns supplemental information about resources produced by the [`resources.GetRemote`][], [`css.Build`][], and [`js.Build`][] functions. |
| 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. Unless otherwise noted, these methods are applicable to resources returned by the `resources.GetRemote` function. |
| 40 |
|
| 41 |
`Artifacts` |
| 42 |
: {{< new-in 0.165.0 />}} |
| 43 |
: (`slice`) Applicable to resources returned by the `css.Build` and `js.Build` functions, a slice of the additional output files published as part of the build, such as source maps and files emitted by esbuild's `file` loader. Each element of the slice provides `MediaType`, `Permalink`, and `RelPermalink` methods. See the Artifacts sections of the [`css.Build`][css artifacts] and [`js.Build`][js artifacts] documentation. |
| 44 |
|
| 45 |
`ContentLength` |
| 46 |
: (`int`) The content length in bytes. |
| 47 |
|
| 48 |
`ContentType` |
| 49 |
: (`string`) The content type. |
| 50 |
|
| 51 |
`Headers` |
| 52 |
: (`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. |
| 53 |
|
| 54 |
`Status` |
| 55 |
: (`string`) The HTTP status text. |
| 56 |
|
| 57 |
`StatusCode` |
| 58 |
: (`int`) The HTTP status code. |
| 59 |
|
| 60 |
`TransferEncoding` |
| 61 |
: (`string`) The transfer encoding. |
| 62 |
|
| 63 |
[`css.Build`]: /functions/css/build/ |
| 64 |
[`js.Build`]: /functions/js/build/ |
| 65 |
[`resources.GetRemote`]: /functions/resources/getremote/ |
| 66 |
[`responseHeaders`]: /functions/resources/getremote/#responseheaders |
| 67 |
[css artifacts]: /functions/css/build/#artifacts |
| 68 |
[js artifacts]: /functions/js/build/#artifacts |