1
0
mirror of https://github.com/golang/go synced 2024-11-17 16:04:47 -07:00

encoding/base64: add package-level example

Fixes #13011.

Change-Id: Ia4c67880fca83f4298ff6bb1b217ec26c8c83427
Reviewed-on: https://go-review.googlesource.com/17231
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Russ Cox 2015-11-25 11:58:06 -05:00 committed by Brad Fitzpatrick
parent 0680e9c0c1
commit e4e4942387

View File

@ -12,6 +12,21 @@ import (
"os"
)
func Example() {
msg := "Hello, 世界"
encoded := base64.StdEncoding.EncodeToString([]byte(msg))
fmt.Println(encoded)
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
fmt.Println("decode error:", err)
return
}
fmt.Println(string(decoded))
// Output:
// SGVsbG8sIOS4lueVjA==
// Hello, 世界
}
func ExampleEncoding_EncodeToString() {
data := []byte("any + old & data")
str := base64.StdEncoding.EncodeToString(data)