資料
Data
方法作用於由 resources.GetRemote
函數返回的資源,返回來自 HTTP 回應的資訊。
{{ $url := "https://example.org/images/a.jpg" }}
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ with .Data }}
{{ .ContentLength }} → 42764
{{ .ContentType }} → image/jpeg
{{ .Status }} → 200 OK
{{ .StatusCode }} → 200
{{ .TransferEncoding }} → []
{{ end }}
{{ end }}
{{ else }}
{{ errorf "無法取得遠端資源 %q" $url }}
{{ end }}
- ContentLength
- (
int
) 內容長度(以位元組為單位)。 - ContentType
- (
string
) 內容類型。 - Status
- (
string
) HTTP 狀態文本。 - StatusCode
- (
int
) HTTP 狀態碼。 - TransferEncoding
- (
string
) 傳輸編碼。