Go1.5 will have a WithPadding
option on Encoding
.
This also will add 2 pre-defined encodings, RawStdEncoding
, and RawURLEncoding
, which will have no padding.
Though since you're on app-engine, and won't have access to Go1.5 for a while, you can make some helper function to add and remove the padding as needed.
Here is an example to encode and decode strings. If you need, it could easily be adapted to work more efficiently using []byte
.
func base64EncodeStripped(s string) string {
encoded := base64.StdEncoding.EncodeToString([]byte(s))
return strings.TrimRight(encoded, "=")
}
func base64DecodeStripped(s string) (string, error) {
if i := len(s) % 4; i != 0 {
s += strings.Repeat("=", 4-i)
}
decoded, err := base64.StdEncoding.DecodeString(s)
return string(decoded), err
}