master
Bel LaPointe 2022-12-27 19:49:34 -05:00
parent c4a1c9ce98
commit 4559e269e0
1 changed files with 9 additions and 5 deletions

View File

@ -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
}