Standard library / encoding/base64

encoding/base64.Encoding.Encode()

Encodes into a destination sized with EncodedLen. Expected stdout: 'R28=\n'.

Formal Syntax & Structure

go syntaxgo
func (enc *Encoding) Encode(dst, src []byte)

Parameters & Attributes

NameTypeDescription
dst[]byteDestination byte slice; append APIs preserve its existing prefix.
src[]byteSource bytes to encode or decode.

Working Example

Example Snippetgo
package main
import (  "encoding/base64"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  p := make([]byte, base64.StdEncoding.EncodedLen(2))  base64.StdEncoding.Encode(p, []byte("Go"))  fmt.Println(string(p))}
Go Reference