base64 encode golang
To encode a string to base64 in Go, you can use the encoding/base64 package. Here are the steps to perform base64 encoding in Go:
- Import the encoding/base64 package:
import (
"encoding/base64"
)
- Convert the string to a byte slice:
str := "Hello, World!"
byteSlice := []byte(str)
- Encode the byte slice to base64:
encoded := base64.StdEncoding.EncodeToString(byteSlice)
- Print the encoded string:
fmt.Println(encoded)
Let me know if you have any further questions.