Standard library / encoding/base64
encoding/base64.NewEncoding()
Constructs a custom encoding with a 64-byte unique alphabet. Invalid alphabets panic. Expected stdout: '_w==\n'.
Formal Syntax & Structure
go syntaxgo
func NewEncoding(encoder string) *EncodingParameters & Attributes
| Name | Type | Description |
|---|---|---|
| encoder | string | Alphabet of 64 distinct byte values. |
Return Value
*Encoding
Base64 encoding configuration.
Working Example
Example Snippetgo
package main
import ( "encoding/base64" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { e := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_") fmt.Println(e.EncodeToString([]byte{255}))}