直接来代码吧:
代码语言:javascript
复制package main
import (
"encoding/base64"
"fmt"
)
func main() {
src := []byte("hello")
ret := base64.StdEncoding.EncodeToString(src)
fmt.Println(ret) //aGVsbG8=
src2, err := base64.StdEncoding.DecodeString(ret) // return bytes
fmt.Println(string(src2), err)
}