27 lines
734 B
Go
27 lines
734 B
Go
package aws
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"regexp"
|
|
)
|
|
|
|
// Base64Encode encodes data if the input isn't already encoded using base64.StdEncoding.EncodeToString.
|
|
// If the input is already base64 encoded, return the original input unchanged.
|
|
func base64Encode(data []byte) string {
|
|
// Check whether the data is already Base64 encoded; don't double-encode
|
|
if isBase64Encoded(data) {
|
|
return string(data)
|
|
}
|
|
// data has not been encoded encode and return
|
|
return base64.StdEncoding.EncodeToString(data)
|
|
}
|
|
|
|
func isBase64Encoded(data []byte) bool {
|
|
_, err := base64.StdEncoding.DecodeString(string(data))
|
|
return err == nil
|
|
}
|
|
|
|
func looksLikeJsonString(s interface{}) bool {
|
|
return regexp.MustCompile(`^\s*{`).MatchString(s.(string))
|
|
}
|