blob: 5237e904fe17a885821efac13ffae90c0fb57381 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
---
title: encoding.Base64Decode
description: Returns the base64 decoding of the given content.
categories: []
keywords: []
params:
functions_and_methods:
aliases: [base64Decode]
returnType: string
signatures: [encoding.Base64Decode INPUT]
aliases: [/functions/base64Decode]
---
```go-html-template
{{ "SHVnbw==" | base64Decode }} → Hugo
```
Use the `base64Decode` function to decode responses from APIs. For example, the result of this call to GitHub's API contains the base64-encoded representation of the repository's README file:
```text
https://api.github.com/repos/gohugoio/hugo/readme
```
To retrieve and render the content:
```go-html-template
{{ $url := "https://api.github.com/repos/gohugoio/hugo/readme" }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else with .Value }}
{{ with . | transform.Unmarshal }}
{{ .content | base64Decode | markdownify }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ end }}
```
|