race
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
@@ -20,6 +21,7 @@ type Server struct {
|
||||
resolver *net.Resolver
|
||||
limiter *rate.Limiter
|
||||
Timeout time.Duration
|
||||
dnsCacheLock sync.Mutex
|
||||
dnsCache map[string]dns
|
||||
}
|
||||
|
||||
@@ -154,6 +156,8 @@ func (s *Server) dig(ctx context.Context, host string) (string, error) {
|
||||
search := host
|
||||
search = strings.TrimPrefix(search, "https://")
|
||||
search = strings.TrimPrefix(search, "http://")
|
||||
s.dnsCacheLock.Lock()
|
||||
defer s.dnsCacheLock.Unlock()
|
||||
if v, ok := s.dnsCache[host]; ok && v.ok() {
|
||||
return v.result, v.err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user