Standard library / encoding/pem
encoding/pem.Encode()
Write a textual PEM block to a writer, returning any header-validation or output error. This wraps bytes, not encrypts or authenticates them. Expected stdout: '-----BEGIN DEMO-----\nR28=\n-----END DEMO-----\n'.
Formal Syntax & Structure
go syntaxgo
func Encode(out io.Writer, b *Block) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| out | io.Writer | Destination writer. |
| b | *Block | PEM block with type label, optional headers and payload bytes. |
Return Value
error
Nil on success; otherwise the operation error.
Working Example
Example Snippetgo
package main
import ( "bytes" "encoding/pem" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var buf bytes.Buffer must(pem.Encode(&buf, &pem.Block{Type: "DEMO", Bytes: []byte("Go")})) fmt.Print(buf.String())}