race
parent
c4a1c9ce98
commit
4559e269e0
14
server.go
14
server.go
|
|
@ -10,17 +10,19 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Transport http.RoundTripper
|
||||
resolver *net.Resolver
|
||||
limiter *rate.Limiter
|
||||
Timeout time.Duration
|
||||
dnsCache map[string]dns
|
||||
Transport http.RoundTripper
|
||||
resolver *net.Resolver
|
||||
limiter *rate.Limiter
|
||||
Timeout time.Duration
|
||||
dnsCacheLock sync.Mutex
|
||||
dnsCache map[string]dns
|
||||
}
|
||||
|
||||
type dns struct {
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue