summaryrefslogtreecommitdiff
path: root/store.go
diff options
context:
space:
mode:
authorDmitry Chestnykh <dmitry@codingrobots.com>2015-03-26 00:35:41 +0300
committerDmitry Chestnykh <dmitry@codingrobots.com>2015-03-26 00:35:41 +0300
commit4b0af472301b1081c4821c65875c9f50824ebd3a (patch)
tree433cbe6b4eecbcb7de4bb860f9504b52ee1d12f8 /store.go
parent1f45645972a051deb63c8e8e3c594041a6145e35 (diff)
Simplify FilesystemStore save and load.
Use ioutil package to write and read files.
Diffstat (limited to 'store.go')
-rw-r--r--store.go28
1 files changed, 3 insertions, 25 deletions
diff --git a/store.go b/store.go
index b3461b0..24b466f 100644
--- a/store.go
+++ b/store.go
@@ -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