1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:20:01 -07:00

encoding/pem: add Encode example

Change-Id: Ib9ec3524b712e016a9dd2fbee5555362c1a0cb59
Reviewed-on: https://go-review.googlesource.com/77770
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Tim Cooper 2017-11-14 21:32:00 -04:00 committed by Brad Fitzpatrick
parent d259815ccb
commit 707a4d3fed

View File

@ -9,6 +9,7 @@ import (
"encoding/pem"
"fmt"
"log"
"os"
)
func ExampleDecode() {
@ -42,3 +43,23 @@ and some more`)
fmt.Printf("Got a %T, with remaining data: %q", pub, rest)
// Output: Got a *rsa.PublicKey, with remaining data: "and some more"
}
func ExampleEncode() {
block := &pem.Block{
Type: "MESSAGE",
Headers: map[string]string{
"Animal": "Gopher",
},
Bytes: []byte("test"),
}
if err := pem.Encode(os.Stdout, block); err != nil {
log.Fatal(err)
}
// Output:
// -----BEGIN MESSAGE-----
// Animal: Gopher
//
// dGVzdA==
// -----END MESSAGE-----
}