HUGO
Menu
GitHub 87548 stars Mastodon

Data

適用於 resources.GetRemote 函數返回的資源,返回來自 HTTP 響應的信息。

Syntax

RESOURCE.Data

Returns

map

resources.GetRemote 函數返回的資源上的 Data 方法返回來自 HTTP 響應的信息。

示例

{{ $url := "https://example.org/images/a.jpg" }}
{{ $opts := dict "responseHeaders" (slice "Server") }}
{{ with try (resources.GetRemote $url) }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else with .Value }}
    {{ with .Data }}
      {{ .ContentLength }} → 42764
      {{ .ContentType }} → image/jpeg
      {{ .Headers }} → map[Server:[Netlify]]
      {{ .Status }} → 200 OK
      {{ .StatusCode }} → 200
      {{ .TransferEncoding }} → []
    {{ end }}
  {{ else }}
    {{ errorf "Unable to get remote resource %q" $url }}
  {{ end }}
{{ end }}

方法

ContentLength

int)內容長度(字節)。

ContentType

string)內容類型。

Headers

map[string][]string)響應頭映射,與傳遞給 resources.GetRemote 函數的 responseHeaders 選項中請求的響應頭匹配。頭名稱匹配不區分大小寫。在大多數情況下,每個頭鍵將有一個值。

Status

string)HTTP 狀態文本。

StatusCode

int)HTTP 狀態碼。

TransferEncoding

string)傳輸編碼。


Last updated: January 1, 0001
Improve this page