Browse Source

wording

master
Lars Hoogestraat 1 month ago
parent
commit
36fd4af4cc
4 changed files with 14 additions and 15 deletions
  1. +1
    -1
      session.go
  2. +4
    -5
      session_provider.go
  3. +2
    -2
      session_service.go
  4. +7
    -7
      session_service_test.go

+ 1
- 1
session.go View File

@ -22,7 +22,7 @@ func (s *Session) GetLastTouchTime() time.Time {
return s.lastTouched
}
//GetSessionID gets the sessionID
//SessionID gets the sessionID
func (s *Session) SessionID() string {
return s.sid
}


+ 4
- 5
session_provider.go View File

@ -59,13 +59,13 @@ func (imp *InMemoryProvider) Get(sid string) (*Session, error) {
return nil, fmt.Errorf("no session with id %s found", sid)
}
//Get receives the session from the map by the session identifier
//SessionIDsFromValues receives all session ids from the map found with the key and value
func (imp *InMemoryProvider) SessionIDsFromValues(key string, value interface{}) []string {
imp.mutex.RLock()
defer imp.mutex.RUnlock()
ids := []string{}
var ids []string
for _, s := range imp.sessions {
if s.values[key] == value {
@ -84,8 +84,7 @@ func (imp *InMemoryProvider) Remove(sid string) {
delete(imp.sessions, sid)
}
//Clean clean sessions after a specified timeout
//Checks every x durations defined in config
//Clean clean sessions after the specified timeout
func (imp *InMemoryProvider) Clean(ticker *time.Ticker, timeoutAfter time.Duration) {
go func() {
for range ticker.C {
@ -98,4 +97,4 @@ func (imp *InMemoryProvider) Clean(ticker *time.Ticker, timeoutAfter time.Durati
imp.mutex.Unlock()
}
}()
}
}

+ 2
- 2
session_service.go View File

@ -12,7 +12,7 @@ import (
"time"
)
//SessionConfig contains settings for the session
//SessionService contains settings for the session
type SessionService struct {
Path string
HTTPOnly bool
@ -68,7 +68,7 @@ func (sc SessionService) Get(rw http.ResponseWriter, r *http.Request) (*Session,
return sess, nil
}
//Renew renews the session from
//Renew renews the session
func (sc SessionService) Renew(rw http.ResponseWriter, r *http.Request) (*Session, error) {
cookie, err := r.Cookie(sc.Name)


+ 7
- 7
session_service_test.go View File

@ -55,11 +55,11 @@ func TestSessionLifeCycle(t *testing.T) {
}
if getSess.SessionID() != session.SessionID() {
t.Fatalf("got an invalid session id. Initial %s, after get %s", session.SessionID(), getSess.SessionID())
t.Fatalf("invalid session id, want %s, got %s", session.SessionID(), getSess.SessionID())
}
if getSess.GetValue("userid") != 3 {
t.Fatalf("the session does not contain the expected userid %d in the session values, got userid %v", 3, session.GetValue("userid"))
t.Fatalf("the session does not contain the expected user id %d in the session values, got userid %v", 3, session.GetValue("userid"))
}
removeSession(t, cookie.Raw, sessionService)
@ -142,18 +142,18 @@ func removeSession(t *testing.T, rawCookieValue string, cs session.SessionServic
func checkCookie(t *testing.T, cookie, expectedCookie *http.Cookie) {
if cookie.Name != expectedCookie.Name {
t.Errorf("got an unexpected cookie name. Expected %s, bot got %s", expectedCookie.Name, cookie.Name)
t.Errorf("unexpected cookie name, want: %s, got: %s", expectedCookie.Name, cookie.Name)
}
if cookie.Path != expectedCookie.Path {
t.Errorf("got an unexpected cookie path. Expected %s, bot got %s", expectedCookie.Path, cookie.Path)
t.Errorf("unexpected cookie path, want: %s, got %s", expectedCookie.Path, cookie.Path)
}
if cookie.Value != expectedCookie.Value {
t.Errorf("got an unexpected cookie value. Expected %s, bot got %s", expectedCookie.Value, cookie.Value)
t.Errorf("unexpected cookie value, want %s, got %s", expectedCookie.Value, cookie.Value)
}
if cookie.HttpOnly != expectedCookie.HttpOnly {
t.Errorf("got an unexpected cookie http only f;ag. Expected %t, bot got %t", expectedCookie.HttpOnly, cookie.HttpOnly)
t.Errorf("unexpected cookie http only flag, want %t, got %t", expectedCookie.HttpOnly, cookie.HttpOnly)
}
if cookie.Secure != expectedCookie.Secure {
t.Errorf("got an unexpected cookie secure flag. Expected %t, bot got %t", expectedCookie.Secure, cookie.Secure)
t.Errorf("unexpected cookie secure flag, want %t, got %t", expectedCookie.Secure, cookie.Secure)
}
}

Loading…
Cancel
Save