mirror of
https://github.com/golang/go
synced 2024-11-23 18:10:04 -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:
parent
d259815ccb
commit
707a4d3fed
@ -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-----
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user