diff --git a/app/db.go b/app/db.go index 59cb371..a3b7c03 100644 --- a/app/db.go +++ b/app/db.go @@ -48,8 +48,10 @@ func (d *db) IsNewFeed() bool { func NewDB(storageDir, feedName string) (DB, error) { dbPath := path.Join(storageDir, fmt.Sprintf("%s.csv", feedName)) - db := db{dbPath: dbPath} - db.seenLinks = map[string]struct{}{} + db := db{ + dbPath: dbPath, + seenLinks: map[string]struct{}{}, + } f, err := os.Open(dbPath) if err != nil { if errors.Is(err, os.ErrNotExist) { diff --git a/limiter/limiter.go b/limiter/limiter.go index d941992..3d48ba8 100644 --- a/limiter/limiter.go +++ b/limiter/limiter.go @@ -11,22 +11,18 @@ type Limiter interface { type limiter struct { tick time.Duration - count uint + count int entries []time.Time - index uint + index int mutex sync.Mutex } -func NewLimiter(tick time.Duration, count uint) Limiter { +func NewLimiter(tick time.Duration, count int) Limiter { l := limiter{ - tick: tick, - count: count, - index: 0, - } - l.entries = make([]time.Time, count) - before := time.Now().Add(-2 * tick) - for i, _ := range l.entries { - l.entries[i] = before + tick: tick, + count: count, + entries: make([]time.Time, count), + index: 0, } return &l }