resolver

package module
v0.0.0-...-3589805 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2017 License: MIT Imports: 7 Imported by: 0

README

resolver

⚡ Simply DNS resolver with timeouts

Based on miekg/dns.

Status

Under development

Installation

go get github.com/joy4eg/resolver

Usage

package main

import (
	"fmt"
	"time"

	"github.com/joy4eg/resolver"
)

func main() {
	ip, err := resolver.ResolveIPv4("reddit.com")
	if err != nil {
		panic(err)
	}
	fmt.Println(ip.String()) // 151.101.1.140

	// Or you can use compat API
	ips, err := resolver.LookupIPTimeout("reddit.com", 1 * time.Second)
	if err != nil {
		panic(err)
	}
	fmt.Println(ips) // [151.101.65.140 151.101.1.140 151.101.193.140 151.101.129.140]
}

Author

joy4eg

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNoHost           = errors.New("no such host")
	ErrorInvalidIPversion = errors.New("invalid IP version given")
)
View Source
var (
	ConfigDefault = Config{
		Servers: []string{
			"208.67.220.220",
			"8.8.4.4",
			"64.6.65.6",
		},
		Timeout:  2 * time.Second,
		Attempts: 2,
	}
)

Default resolver configuration

Functions

func LookupAddrTimeout

func LookupAddrTimeout(addr string, timeout time.Duration) (names []string, err error)

LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.

func LookupIPTimeout

func LookupIPTimeout(host string, timeout time.Duration) (ips []net.IP, err error)

LookupIP looks up host using the configured resolver. It returns an array of that host's IPv4 and IPv6 addresses.

func ResolveIPVersion

func ResolveIPVersion(version IPVersion, addr string) (ip net.IP, err error)

func ResolveIPv4

func ResolveIPv4(addr string) (ip net.IP, err error)

func ResolveIPv6

func ResolveIPv6(addr string) (ip net.IP, err error)

func ResolveIPvALL

func ResolveIPvALL(addr string) (ips []net.IP, err error)

func ResolveIPvAUTO

func ResolveIPvAUTO(addr string) (ip net.IP, err error)

func ResolvePTR

func ResolvePTR(ip string) (host string, err error)

func SetConfig

func SetConfig(c Config)

SetConfig sets the resolver configuration

Types

type Config

type Config struct {
	Servers  []string      // servers to use
	Timeout  time.Duration // a cumulative timeout for dial, write and read, defaults to 2s
	Attempts int           // Total number of resolving attempts
}

Resolver configuration

type IPVersion

type IPVersion string
const (
	IPv4    IPVersion = "ipv4"
	IPv6    IPVersion = "ipv6"
	IPvAUTO IPVersion = "auto"
)

Jump to

Keyboard shortcuts

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