前端之家收集整理的这篇文章主要介绍了
golang base64,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
// test12 project main.go
package main
import (
"bytes"
"encoding/base64"
"fmt"
)
func main() {
eightBitData := []byte{1,2,3,4,5,6,7,8}
bb := &bytes.Buffer{}
encoder := base64.NewEncoder(base64.StdEncoding,bb)
encoder.Write(eightBitData)
encoder.Close()
fmt.Println(bb)
decoder := base64.NewDecoder(base64.StdEncoding,bb)
dbuf := make([]byte,12)
decoder.Read(dbuf)
for _,v := range dbuf {
fmt.Println(v)
}
gg := &bytes.Buffer{}
encoder = base64.NewEncoder(base64.StdEncoding,gg)
tt := "ddddddddddddd"
encoder.Write([]byte(tt))
fmt.Println(gg)
hh := make([]byte,20)
decoder = base64.NewDecoder(base64.StdEncoding,gg)
decoder.Read(hh)
fmt.Println("content:" + string(hh))
}