Skip to content

Instantly share code, notes, and snippets.

@mgenov
Created February 7, 2014 12:29
Show Gist options
  • Save mgenov/8861806 to your computer and use it in GitHub Desktop.
Save mgenov/8861806 to your computer and use it in GitHub Desktop.
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