Commit 707a4d3f authored by Tim Cooper's avatar Tim Cooper Committed by Brad Fitzpatrick

encoding/pem: add Encode example

Change-Id: Ib9ec3524b712e016a9dd2fbee5555362c1a0cb59
Reviewed-on: https://go-review.googlesource.com/77770Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d259815c
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"log" "log"
"os"
) )
func ExampleDecode() { func ExampleDecode() {
...@@ -42,3 +43,23 @@ and some more`) ...@@ -42,3 +43,23 @@ and some more`)
fmt.Printf("Got a %T, with remaining data: %q", pub, rest) fmt.Printf("Got a %T, with remaining data: %q", pub, rest)
// Output: Got a *rsa.PublicKey, with remaining data: "and some more" // 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-----
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment