Goの標準ライブラリでDNSの名前解決
code:go
package main
import (
"context"
"fmt"
"net"
"time"
)
func main() {
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
return d.DialContext(ctx, "udp", "1.1.1.1:53")
},
}
ip, _ := r.LookupHost(context.Background(), "example.com")
}