github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/encoding/base64/url.base64.go (about) 1 package base64 2 3 import "encoding/base64" 4 5 //URLEncodeBytes 把一个[]byte通过base64编码成string 6 func URLEncodeBytes(src []byte) string { 7 return base64.URLEncoding.EncodeToString(src) 8 } 9 10 //URLDecodeBytes 把一个string通过base64解码成[]byte 11 func URLDecodeBytes(src string) (s []byte, err error) { 12 s, err = base64.URLEncoding.DecodeString(src) 13 return 14 } 15 16 //URLEncode 把一个string通过base64编码 17 func URLEncode(src string) string { 18 return URLEncodeBytes([]byte(src)) 19 } 20 21 //URLDecode 把一个string通过base64解码 22 func URLDecode(src string) (s string, err error) { 23 buf, err := URLDecodeBytes(src) 24 if err != nil { 25 return 26 } 27 s = string(buf) 28 return 29 }