mirror of
https://github.com/SajadMRjl/find-me-internet.git
synced 2026-07-02 15:09:00 +00:00
36 lines
509 B
Go
36 lines
509 B
Go
package dedup
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
type Filter struct {
|
|
seen map[string]struct{}
|
|
mu sync.RWMutex
|
|
}
|
|
|
|
func New() *Filter {
|
|
return &Filter{
|
|
seen: make(map[string]struct{}),
|
|
}
|
|
}
|
|
|
|
// Check returns true if the item is NEW (not seen before)
|
|
func (f *Filter) Seen(address string, port int) bool {
|
|
key := fmt.Sprintf("%s:%d", address, port)
|
|
|
|
f.mu.RLock()
|
|
_, exists := f.seen[key]
|
|
f.mu.RUnlock()
|
|
|
|
if exists {
|
|
return true
|
|
}
|
|
|
|
f.mu.Lock()
|
|
f.seen[key] = struct{}{}
|
|
f.mu.Unlock()
|
|
|
|
return false
|
|
} |