Standard library / encoding/pem
encoding/pem.EncodeToMemory()
Return the complete PEM representation in memory. Invalid headers may yield nil; use Encode when error details matter. Expected stdout: '-----BEGIN DEMO-----\nR28=\n-----END DEMO-----\n'.
Formal Syntax & Structure
go syntaxgo
func EncodeToMemory(b *Block) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| b | *Block | PEM block with type label, optional headers and payload bytes. |
Return Value
[]byte
Encoded or extended byte slice.
Working Example
Example Snippetgo
package main
import ( "encoding/pem" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { fmt.Print(string(pem.EncodeToMemory(&pem.Block{Type: "DEMO", Bytes: []byte("Go")}))) }