Skip to content

whois-api-llc/subdomains-lookup-go

Repository files navigation

subdomains-lookup-go license subdomains-lookup-go made-with-Go subdomains-lookup-go test

Overview

The client library for Subdomains Lookup API in Go language.

The minimum go version is 1.17.

Installation

The library is distributed as a Go module

go get github.com/whois-api-llc/subdomains-lookup-go

Examples

Full API documentation available here

You can find all examples in example directory.

Create a new client

To start making requests you need the API Key. You can find it on your profile page on whoisxmlapi.com. Using the API Key you can create Client.

Most users will be fine with NewBasicClient function.

client := subdomainslookup.NewBasicClient(apiKey)

If you want to set custom http.Client to use proxy then you can use NewClient function.

transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

client := subdomainslookup.NewClient(apiKey, subdomainslookup.ClientParams{
    HTTPClient: &http.Client{
        Transport: transport,
        Timeout:   20 * time.Second,
    },
})

Make basic requests

Subdomains Lookup API lets you get a list of all subdomains related to a given domain name.

// Make request to get all subdomains for the domain name.
subdomainsLookupResp, resp, err := client.Get(ctx, "whoisxmlapi.com")
if err != nil {
    log.Fatal(err)
}

for _, obj := range subdomainsLookupResp.Result.Records {
    log.Printf("Domain: %s, FirstSeen: %s, LastSeen: %s\n", 
		obj.Domain, 
		time.Unix(obj.FirstSeen, 0).Format(time.RFC3339), 
		time.Unix(obj.LastSeen, 0).Format(time.RFC3339),
    )
}

// Make request to get raw data from Subdomains Lookup API.
resp, err := client.GetRaw(context.Background(), "whoisxmlapi.com")
if err != nil {
    log.Fatal(err)
}

log.Println(string(resp.Body))