Created
February 7, 2014 12:29
-
-
Save mgenov/8861806 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app | |
import ( | |
"fmt" | |
"time" | |
) | |
type SessionClock interface { | |
SessionDuration() time.Duration | |
} | |
type SessionRepository struct { | |
clock SessionClock | |
} | |
type Session struct { | |
Id string | |
ExpirationTime time.Time | |
} | |
func (s SessionRepository) UpdateSessionTime(sessionId string) Session { | |
time := s.clock.SessionDuration() | |
// load existing session from datastore (mongodb) | |
session := Session{sessionId, time} | |
// update time | |
session.UpdateExpirationTime(time) | |
// store session in datastore | |
return session | |
} | |
func (s Session) UpdateExpirationTime(time.Time time) bool{ | |
return s.ExpirationTime(time) | |
} | |
func (s SessionRepository) IsSessionExpired(sessionId string) bool { | |
} | |
type realClock struct{} | |
func (r realClock) Now() time.Time { | |
return time.Now() | |
} | |
func DoSomething(clock Clock) { | |
time := clock.Now() | |
fmt.Printf("%s\n", time) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment