-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs/howto: use encoding/base64.{De,En}code
This adds a pair of Commented CUE guides demonstrating how to use the built-in functions encoding/base64.Decode and encoding/base64.Encode. The Decode example needs to include a string interpolation that's not strictly related to the function's use case, as otherwise "cue export" Base64-encodes the function's []byte return in the terminal output, which would likely confuse the reader. Preview-Path: /docs/howto/use-the-built-in-function-encoding-base64-decode/ Preview-Path: /docs/howto/use-the-built-in-function-encoding-base64-encode/ Signed-off-by: Jonathan Matthews <[email protected]> Change-Id: I631c77d8028596e1420067d24ed9b99d07b23465 Dispatch-Trailer: {"type":"trybot","CL":1174178,"patchset":7,"ref":"refs/changes/78/1174178/7","targetBranch":"alpha"}
- Loading branch information
1 parent
84b0150
commit df989e3
Showing
8 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
content/docs/howto/use-the-built-in-function-encoding-base64-decode/en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: Using the built-in function "encoding/base64.Decode" | ||
tags: | ||
- commented cue | ||
- encodings | ||
authors: | ||
- jpluscplusm | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to use the built-in function `encoding/base64.Decode` to decode | ||
data that is encoded as Base64. | ||
|
||
{{{with code "en" "cc"}}} | ||
#location left right | ||
|
||
exec cue export | ||
cmp stdout out | ||
-- file.cue -- | ||
package example | ||
|
||
import "encoding/base64" | ||
|
||
// encoded contains some Base64-encoded data | ||
encoded: "c29tZSBCYXNlNjQtZW5jb2RlZCBkYXRh" | ||
|
||
// decoded contains the string interpolation of | ||
// the byte array returned by base64.Decode | ||
decoded: "\(base64.Decode(null, encoded))" | ||
-- out -- | ||
{ | ||
"encoded": "c29tZSBCYXNlNjQtZW5jb2RlZCBkYXRh", | ||
"decoded": "some Base64-encoded data" | ||
} | ||
{{{end}}} | ||
|
||
## Related content | ||
|
||
- The [`encoding/base64`](https://pkg.go.dev/cuelang.org/go/pkg/encoding/base64) built-in package |
18 changes: 18 additions & 0 deletions
18
content/docs/howto/use-the-built-in-function-encoding-base64-decode/gen_cache.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package site | ||
{ | ||
content: { | ||
docs: { | ||
howto: { | ||
"use-the-built-in-function-encoding-base64-decode": { | ||
page: { | ||
cache: { | ||
code: { | ||
cc: "5qOOo7lThAkQspaLSGP6So5m0bZynVbxIz6YDilXheY=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
content/docs/howto/use-the-built-in-function-encoding-base64-decode/page.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: docs: howto: "use-the-built-in-function-encoding-base64-decode": {} |
36 changes: 36 additions & 0 deletions
36
content/docs/howto/use-the-built-in-function-encoding-base64-encode/en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Using the built-in function "encoding/base64.Encode" | ||
tags: | ||
- commented cue | ||
- encodings | ||
authors: | ||
- jpluscplusm | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to use the built-in function `encoding/base64.Encode` to | ||
encode a string as Base64. | ||
|
||
{{{with code "en" "cc"}}} | ||
#location left right | ||
|
||
exec cue export | ||
cmp stdout out | ||
-- file.cue -- | ||
package example | ||
|
||
import "encoding/base64" | ||
|
||
decoded: "some string" | ||
encoded: base64.Encode(null, decoded) | ||
-- out -- | ||
{ | ||
"decoded": "some string", | ||
"encoded": "c29tZSBzdHJpbmc=" | ||
} | ||
{{{end}}} | ||
|
||
## Related content | ||
|
||
- The [`encoding/base64`](https://pkg.go.dev/cuelang.org/go/pkg/encoding/base64) built-in package |
18 changes: 18 additions & 0 deletions
18
content/docs/howto/use-the-built-in-function-encoding-base64-encode/gen_cache.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package site | ||
{ | ||
content: { | ||
docs: { | ||
howto: { | ||
"use-the-built-in-function-encoding-base64-encode": { | ||
page: { | ||
cache: { | ||
code: { | ||
cc: "QokSidgCx1xEkbL8TgJpHrJ9gfxIoDOxQElKSlf0JSY=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
content/docs/howto/use-the-built-in-function-encoding-base64-encode/page.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: docs: howto: "use-the-built-in-function-encoding-base64-encode": {} |
39 changes: 39 additions & 0 deletions
39
...content/en/docs/howto/use-the-built-in-function-encoding-base64-decode/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: Using the built-in function "encoding/base64.Decode" | ||
tags: | ||
- commented cue | ||
- encodings | ||
authors: | ||
- jpluscplusm | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to use the built-in function `encoding/base64.Decode` to decode | ||
data that is encoded as Base64. | ||
|
||
{{< code-tabs >}} | ||
{{< code-tab name="file.cue" language="cue" area="left" >}} | ||
package example | ||
|
||
import "encoding/base64" | ||
|
||
// encoded contains some Base64-encoded data | ||
encoded: "c29tZSBCYXNlNjQtZW5jb2RlZCBkYXRh" | ||
|
||
// decoded contains the string interpolation of | ||
// the byte array returned by base64.Decode | ||
decoded: "\(base64.Decode(null, encoded))" | ||
{{< /code-tab >}} | ||
{{< code-tab name="TERMINAL" language="" type="terminal" area="right" >}} | ||
$ cue export | ||
{ | ||
"encoded": "c29tZSBCYXNlNjQtZW5jb2RlZCBkYXRh", | ||
"decoded": "some Base64-encoded data" | ||
} | ||
{{< /code-tab >}} | ||
{{< /code-tabs >}} | ||
|
||
## Related content | ||
|
||
- The [`encoding/base64`](https://pkg.go.dev/cuelang.org/go/pkg/encoding/base64) built-in package |
35 changes: 35 additions & 0 deletions
35
...content/en/docs/howto/use-the-built-in-function-encoding-base64-encode/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: Using the built-in function "encoding/base64.Encode" | ||
tags: | ||
- commented cue | ||
- encodings | ||
authors: | ||
- jpluscplusm | ||
toc_hide: true | ||
--- | ||
|
||
This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) | ||
demonstrates how to use the built-in function `encoding/base64.Encode` to | ||
encode a string as Base64. | ||
|
||
{{< code-tabs >}} | ||
{{< code-tab name="file.cue" language="cue" area="left" >}} | ||
package example | ||
|
||
import "encoding/base64" | ||
|
||
decoded: "some string" | ||
encoded: base64.Encode(null, decoded) | ||
{{< /code-tab >}} | ||
{{< code-tab name="TERMINAL" language="" type="terminal" area="right" >}} | ||
$ cue export | ||
{ | ||
"decoded": "some string", | ||
"encoded": "c29tZSBzdHJpbmc=" | ||
} | ||
{{< /code-tab >}} | ||
{{< /code-tabs >}} | ||
|
||
## Related content | ||
|
||
- The [`encoding/base64`](https://pkg.go.dev/cuelang.org/go/pkg/encoding/base64) built-in package |