Skip to content

Commit

Permalink
Merge pull request #99 from verygoodsoftwarenotvirus/master
Browse files Browse the repository at this point in the history
Improve Tests
  • Loading branch information
alexedwards authored Jul 29, 2020
2 parents 40c2a5f + 60e4f10 commit 8c9ddd4
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 32 deletions.
6 changes: 2 additions & 4 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func (GobCodec) Encode(deadline time.Time, values map[string]interface{}) ([]byt
}

var b bytes.Buffer
err := gob.NewEncoder(&b).Encode(&aux)
if err != nil {
if err := gob.NewEncoder(&b).Encode(&aux); err != nil {
return nil, err
}

Expand All @@ -44,8 +43,7 @@ func (GobCodec) Decode(b []byte) (time.Time, map[string]interface{}, error) {
}{}

r := bytes.NewReader(b)
err := gob.NewDecoder(r).Decode(&aux)
if err != nil {
if err := gob.NewDecoder(r).Decode(&aux); err != nil {
return time.Time{}, nil, err
}

Expand Down
10 changes: 4 additions & 6 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func (s *SessionManager) Load(ctx context.Context, token string) (context.Contex
status: Unmodified,
token: token,
}
sd.deadline, sd.values, err = s.Codec.Decode(b)
if err != nil {
if sd.deadline, sd.values, err = s.Codec.Decode(b); err != nil {
return nil, err
}

// Mark the session data as modified if an idle timeout is being used. This
// will force the session data to be re-committed to the session store with
// a new expiry time.
Expand All @@ -97,8 +97,7 @@ func (s *SessionManager) Commit(ctx context.Context) (string, time.Time, error)

if sd.token == "" {
var err error
sd.token, err = generateToken()
if err != nil {
if sd.token, err = generateToken(); err != nil {
return "", time.Time{}, err
}
}
Expand All @@ -116,8 +115,7 @@ func (s *SessionManager) Commit(ctx context.Context) (string, time.Time, error)
}
}

err = s.Store.Commit(sd.token, b, expiry)
if err != nil {
if err := s.Store.Commit(sd.token, b, expiry); err != nil {
return "", time.Time{}, err
}

Expand Down
Loading

0 comments on commit 8c9ddd4

Please sign in to comment.