1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-10 02:30:18 +00:00

session: #620 make the session never read empty

This commit is contained in:
astaxie
2014-05-27 15:45:35 +08:00
parent c3a23b28ee
commit d2eece9a39
2 changed files with 9 additions and 5 deletions

View File

@ -20,6 +20,8 @@ import (
"io"
"strconv"
"time"
"github.com/astaxie/beego/utils"
)
func init() {
@ -60,8 +62,8 @@ func DecodeGob(encoded []byte) (map[interface{}]interface{}, error) {
// generateRandomKey creates a random key with the given strength.
func generateRandomKey(strength int) []byte {
k := make([]byte, strength)
if _, err := io.ReadFull(rand.Reader, k); err != nil {
return nil
if n, err := io.ReadFull(rand.Reader, k); n != strength || err != nil {
return utils.RandomCreateBytes(strength)
}
return k
}