Documentation
¶
Overview ¶
Package dns provides DNS-over-HTTPS resolution with caching support for the httpc library.
Index ¶
- 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoHResolver ¶
type DoHResolver struct {
// contains filtered or unexported fields
}
DoHResolver provides DNS-over-HTTPS resolution
func NewDoHResolver ¶
func NewDoHResolver(providers []*dohProvider, cacheTTL time.Duration) *DoHResolver
NewDoHResolver creates a new DoH resolver. Passing nil or an empty providers slice selects defaultDoHProviders(); custom providers can only be supplied within this package (the dohProvider type is unexported).
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). Currently exercised only by tests; admission control reads the atomic directly.
func (*DoHResolver) ClearCache ¶
func (r *DoHResolver) ClearCache()
ClearCache clears the DNS cache. Deletes all entries and atomically resets the counter to zero.
The final recount is approximate under concurrency: an entry admitted between the counting Range and the Store can leave the counter slightly below the true size, so the cache may transiently exceed maxDoHCacheSize by the number of concurrent admissions. The overshoot is bounded by caller concurrency (never unbounded) and self-corrects at the next admission check, which re-reads and evicts.
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. Currently exercised only by tests; lookups read the atomic directly.
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. Currently exercised only by tests; construction uses the Config field.