diff options
Diffstat (limited to 'store.go')
-rw-r--r-- | store.go | 28 |
1 files changed, 3 insertions, 25 deletions
@@ -6,7 +6,7 @@ package sessions import ( "encoding/base32" - "io" + "io/ioutil" "net/http" "os" "strings" @@ -218,38 +218,16 @@ func (s *FilesystemStore) save(session *Session) error { filename := s.path + "session_" + session.ID fileMutex.Lock() defer fileMutex.Unlock() - fp, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return err - } - defer fp.Close() - if _, err = fp.Write([]byte(encoded)); err != nil { - return err - } - return nil + return ioutil.WriteFile(filename, []byte(encoded), 0600) } // load reads a file and decodes its content into session.Values. func (s *FilesystemStore) load(session *Session) error { filename := s.path + "session_" + session.ID - fp, err := os.OpenFile(filename, os.O_RDONLY, 0400) + fdata, err := ioutil.ReadFile(filename) if err != nil { return err } - defer fp.Close() - var fdata []byte - buf := make([]byte, 128) - for { - var n int - n, err = fp.Read(buf[0:]) - fdata = append(fdata, buf[0:n]...) - if err != nil { - if err == io.EOF { - break - } - return err - } - } if err = securecookie.DecodeMulti(session.Name(), string(fdata), &session.Values, s.Codecs...); err != nil { return err |