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"
"net/http" "net/http"
"strings" "strings"
"sync"
"time" "time"
"golang.org/x/time/rate" "golang.org/x/time/rate"
) )
type Server struct { type Server struct {
Transport http.RoundTripper Transport http.RoundTripper
resolver *net.Resolver resolver *net.Resolver
limiter *rate.Limiter limiter *rate.Limiter
Timeout time.Duration Timeout time.Duration
dnsCache map[string]dns dnsCacheLock sync.Mutex
dnsCache map[string]dns
} }
type dns struct { type dns struct {
@ -154,6 +156,8 @@ func (s *Server) dig(ctx context.Context, host string) (string, error) {
search := host search := host
search = strings.TrimPrefix(search, "https://") search = strings.TrimPrefix(search, "https://")
search = strings.TrimPrefix(search, "http://") search = strings.TrimPrefix(search, "http://")
s.dnsCacheLock.Lock()
defer s.dnsCacheLock.Unlock()
if v, ok := s.dnsCache[host]; ok && v.ok() { if v, ok := s.dnsCache[host]; ok && v.ok() {
return v.result, v.err return v.result, v.err
} }