mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-12 12:09:56 +01:00
36 lines
409 B
Go
36 lines
409 B
Go
package clock
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type Clock interface {
|
|
Now() time.Time
|
|
}
|
|
|
|
type clock struct{}
|
|
|
|
func (clock) Now() time.Time {
|
|
return time.Now()
|
|
}
|
|
|
|
func New() Clock {
|
|
return &clock{}
|
|
}
|
|
|
|
type mockClock struct {
|
|
mu sync.Mutex
|
|
now time.Time
|
|
}
|
|
|
|
func (m *mockClock) Now() time.Time {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
return m.now
|
|
}
|
|
|
|
func Mock() Clock {
|
|
return &mockClock{now: time.Unix(0, 0)}
|
|
}
|