MCPcopy Create free account
hub / github.com/mmcgrana/gobyexample / main

Function main

examples/base64-encoding/base64-encoding.go:14–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func main() {
15
16 // Here's the `string` we'll encode/decode.
17 data := "abc123!?$*&()'-=@~"
18
19 // Go supports both standard and URL-compatible
20 // base64. Here's how to encode using the standard
21 // encoder. The encoder requires a `[]byte` so we
22 // convert our `string` to that type.
23 sEnc := b64.StdEncoding.EncodeToString([]byte(data))
24 fmt.Println(sEnc)
25
26 // Decoding may return an error, which you can check
27 // if you don't already know the input to be
28 // well-formed.
29 sDec, _ := b64.StdEncoding.DecodeString(sEnc)
30 fmt.Println(string(sDec))
31 fmt.Println()
32
33 // This encodes/decodes using a URL-compatible base64
34 // format.
35 uEnc := b64.URLEncoding.EncodeToString([]byte(data))
36 fmt.Println(uEnc)
37 uDec, _ := b64.URLEncoding.DecodeString(uEnc)
38 fmt.Println(string(uDec))
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected