mirror of
https://gitee.com/johng/gf
synced 2026-07-04 21:03:13 +08:00
fix issue in gbase64.Decode
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user