This syntax imports the encoding/base64 package with the b64 name instead of the default 64. It'll save us some space below
package main import ( b64 "encoding/base64" "fmt" ) func main() { data := "abc123!?$*&()'-=@~" sEnc := b64.StdEncoding.EncodeToString([]byte(data)) fmt.Println(sEnc) sDec, _ := b64.StdEncoding.DecodeString(sEnc) fmt.Println(string(sDec)) uEnc := b64.URLEncoding.EncodeToString([]byte(data)) fmt.Println(uEnc) uDec, _ := b64.URLEncoding.DecodeString(uEnc) fmt.Println(string(uDec)) }
YWJjMTIzIT8kKiYoKSctPUB+ abc123!?$*&()'-=@~ YWJjMTIzIT8kKiYoKSctPUB- abc123!?$*&()'-=@~
总结 :
1 : ....
有疑问加站长微信联系(非本文作者)