openRDAP github query help

Tested a code set on my side. It’s working fine.

Code
package main

import (
	"context"
	"fmt"
	"net/http"
	"time"

	"github.com/openrdap/rdap"
	"github.com/openrdap/rdap/bootstrap"
)

func simpleQuery(s string) *rdap.Domain {
	client := &rdap.Client{}

	domain, err := client.QueryDomain(s)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return nil
	}

	return domain
}

func customizeQuery(ctx context.Context,
	c *http.Client,
	b *bootstrap.Client,
	s string) *rdap.Domain {
	req := &rdap.Request{
		Type:       rdap.DomainRequest,
		Query:      s,
		FetchRoles: []string{"all"},
		Timeout:    45 * time.Second,
	}
	req = req.WithContext(ctx)

	client := &rdap.Client{}
	client.HTTP = c
	client.Bootstrap = b

	resp, err := client.Do(req)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return nil
	}

	if d, ok := resp.Object.(*rdap.Domain); ok {
		return d
	}
	return nil
}

// MAINS

func basicMain() {
	d := simpleQuery("google.com")
	if d == nil {
		return
	}

	fmt.Printf("BASIC: Handle=%s Domain=%s\n", d.Handle, d.LDHName)
}

func advancedMain() {
	ctx, cancel := context.WithTimeout(context.TODO(), 45*time.Second)
	defer cancel()

	c := &http.Client{
		Timeout: 60 * time.Second,
	}

	b := &bootstrap.Client{}
	// read up to customize bootstrap

	d := customizeQuery(ctx, c, b, "google.com")
	if d == nil {
		return
	}

	fmt.Printf("ADV  : Handle=%s Domain=%s\n", d.Handle, d.LDHName)
}

func main() {
	basicMain()
	advancedMain()
}
// Output:
// BASIC: Handle=2138514_DOMAIN_COM-VRSN Domain=GOOGLE.COM
// ADV  : Handle=2138514_DOMAIN_COM-VRSN Domain=GOOGLE.COM

There are the things I’m looking at that might cause problem:

  1. The basic is performing a domain request while the advanced is performing nameserver request. From your final checking for advanced code, you’re casting to domain type instead of nameserver type.
  2. I actually drop the url.Parse where it makes no sense to me to perform double querying (disclaimer: i’m not the content expert).
  3. There are a lot of request types available so be sure to understand the entire package before proceeding. Link: https://github.com/openrdap/rdap/blob/master/request.go
  4. Another thing that does not make sense to me is setting the timeout all over the place (http client, then rdap client again). I think rdap is ready as it is for you to perform query directly withou too much customization.
1 Like