resolver

package
v0.6.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resolver 让程序的出站域名解析使用自定义 DNS 服务器,支持普通 DNS 与 DNS over HTTPS。

服务器写法:

223.5.5.5              普通 DNS,默认 53 端口
223.5.5.5:5353         普通 DNS,指定端口
doh@223.5.5.5          DoH,地址为 https://223.5.5.5/dns-query
doh@dns.alidns.com/x   DoH,自定义路径
https://doh.pub/dns-query

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current added in v0.6.6

func Current() *net.Resolver

Current 返回当前生效的全局解析器,供需要显式解析的代码使用(不要直接读 net.DefaultResolver)。

func Dialer added in v0.6.6

func Dialer(d *net.Dialer) *net.Dialer

Dialer 返回 d 的副本,其 Resolver 为空时填入当前解析器。net.Dialer 在 Resolver 为空时会在拨号时直接读 net.DefaultResolver,与保存 DNS 设置时 Install 的写入构成数据竞争;需要拨号的代码应在每次拨号时调用它取副本。

func Install

func Install(list []string) error

Install 设置全局解析器;list 为空时恢复系统默认。无效项被忽略并返回错误。

func New

func New(servers []Server) *net.Resolver

New 创建依次尝试各服务器的解析器。

func Validate

func Validate(list []string) error

Validate 校验一组服务器配置。

Types

type Server

type Server struct {
	// Addr 为普通 DNS 的 IP:端口;DoH 时为空
	Addr string
	// URL 为 DoH 地址
	URL string
}

Server 是解析后的一个 DNS 服务器。

func Parse

func Parse(s string) (Server, error)

Parse 解析一项服务器配置。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL