Files
FixIt/layouts/_partials/function/get-remote-json.html
T

22 lines
684 B
HTML

{{- $response := dict -}}
{{- $url := .URL -}}
{{- $options := .OPTIONS | default dict -}}
{{- if not $url -}}
{{- erroridf "error-get-remote-json" "URL parameter is required!" -}}
{{- end -}}
{{- $cacheKey := print $url (now.Format "2006-01-02") -}}
{{- $options = $options | merge (dict "key" $cacheKey "timeout" "3s") -}}
{{- with try (resources.GetRemote $url $options) -}}
{{- with .Err -}}
{{- erroridf "error-get-remote-json" "%s" . -}}
{{- else with .Value -}}
{{- $response = .Content | transform.Unmarshal -}}
{{- else -}}
{{- erroridf "error-get-remote-json" "Failed to get remote JSON %q" $url -}}
{{- end -}}
{{- end -}}
{{- return $response -}}