fix issue in gbase64.Decode

This commit is contained in:
john
2019-07-09 08:07:50 +08:00
parent 8669057681
commit 3b0012ec30
2 changed files with 12 additions and 22 deletions

View File

@ -22,10 +22,7 @@ func Encode(src []byte) []byte {
func Decode(dst []byte) ([]byte, error) {
src := make([]byte, base64.StdEncoding.DecodedLen(len(dst)))
n, err := base64.StdEncoding.Decode(src, dst)
if err != nil {
return nil, err
}
return src[:n], nil
return src[:n], err
}
// EncodeString encodes bytes with BASE64 algorithm.

View File

@ -1,26 +1,19 @@
package main
import (
"encoding/base64"
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/encoding/gbase64"
)
type User struct {
Uid int
Name string
}
func main() {
if r, err := g.DB().Table("user").Where("uid=?", 1).One(); r != nil {
u := new(User)
if err := r.ToStruct(u); err == nil {
fmt.Println(" uid:", u.Uid)
fmt.Println("name:", u.Name)
} else {
fmt.Println(err)
}
} else if err != nil {
fmt.Println(err)
}
data := "HwHsGhXMaGc==="
datab, err := gbase64.Decode([]byte(data))
fmt.Println(err)
fmt.Println(datab)
fmt.Println(string(datab))
s, e := base64.StdEncoding.DecodeString(data)
fmt.Println(e)
fmt.Println(string(s))
}