Documentation
¶
Index ¶
- type CacheEntry
- type DoHProvider
- type DoHResolver
- func (r *DoHResolver) CacheSize() int64
- func (r *DoHResolver) ClearCache()
- func (r *DoHResolver) Close() error
- func (r *DoHResolver) GetCacheTTL() time.Duration
- func (r *DoHResolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
- func (r *DoHResolver) SetCacheTTL(ttl time.Duration)
- type Resolver
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheEntry ¶
type CacheEntry struct {
IPs []net.IPAddr
Expires time.Time
// contains filtered or unexported fields
}
CacheEntry holds cached DNS resolution results
type DoHProvider ¶
type DoHProvider struct {
Name string
Template string // URL template with {name} placeholder
Priority int
}
DoHProvider represents a DoH service provider
func DefaultDoHProviders ¶
func DefaultDoHProviders() []*DoHProvider
DefaultDoHProviders returns common DoH providers
type DoHResolver ¶
type DoHResolver struct {
// contains filtered or unexported fields
}
DoHResolver provides DNS-over-HTTPS resolution
Example ¶
resolver := NewDoHResolver(nil, 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
ips, err := resolver.LookupIPAddr(ctx, "www.example.com")
if err != nil {
fmt.Printf("DNS resolution failed: %v\n", err)
return
}
fmt.Printf("Resolved to %d IP addresses:\n", len(ips))
for _, ip := range ips {
fmt.Printf(" %s\n", ip.IP.String())
}
func NewDoHResolver ¶
func NewDoHResolver(providers []*DoHProvider, cacheTTL time.Duration) *DoHResolver
NewDoHResolver creates a new DoH resolver
func (*DoHResolver) CacheSize ¶ added in v1.3.8
func (r *DoHResolver) CacheSize() int64
CacheSize returns the current number of entries in the cache (O(1) via atomic counter)
func (*DoHResolver) ClearCache ¶
func (r *DoHResolver) ClearCache()
ClearCache clears the DNS cache SECURITY: Uses atomic counter reset to avoid race conditions with concurrent cache operations. The counter may be temporarily inaccurate during clear but will self-correct on subsequent operations.
func (*DoHResolver) Close ¶ added in v1.3.8
func (r *DoHResolver) Close() error
Close releases resources held by the DoHResolver. It closes idle connections in the internal HTTP client's transport. Safe to call multiple times - subsequent calls are no-ops. Implements io.Closer for consistent resource management.
func (*DoHResolver) GetCacheTTL ¶ added in v1.3.8
func (r *DoHResolver) GetCacheTTL() time.Duration
GetCacheTTL returns the current cache TTL duration. Thread-safe: can be called concurrently with other operations.
func (*DoHResolver) LookupIPAddr ¶
LookupIPAddr resolves a host name to IP addresses using DoH
func (*DoHResolver) SetCacheTTL ¶
func (r *DoHResolver) SetCacheTTL(ttl time.Duration)
SetCacheTTL sets the cache TTL duration. Thread-safe: can be called concurrently with other operations.
type Resolver ¶ added in v1.3.8
type Resolver interface {
// LookupIPAddr resolves a host name to IP addresses.
// It returns a slice of net.IPAddr and any error encountered.
LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
// ClearCache clears any cached DNS entries.
ClearCache()
}
Resolver defines the interface for DNS resolution. Implementations can provide different resolution strategies (DoH, system DNS, etc.)