You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kayos@tcp.direct 4ded087820 implementing faster json library 3 months ago
protocol Merge branch 'gtlds' 9 months ago
LICENSE.txt Add License.txt (#28) 2 years ago
README.md Change RDAP library API to return the RDAP HTTP header response 6 years ago
client.go implementing faster json library 3 months ago
doc.go Fix golint warnings 6 years ago
go.mod implementing faster json library 3 months ago
go.sum implementing faster json library 3 months ago
service_registry.go Migrate from miekg idn to golang idna package 4 years ago
transport.go implementing faster json library 3 months ago

README.md

GoDoc

RDAP

RDAP (Registration Data Access Protocol) is a library to be used in clients and servers to make the life easier when building requests and responses. You will find all RDAP protocol types in the protocol package and can use the clients to build your own client tool.

Implements the RFCs:

  • 7480 - HTTP Usage in the Registration Data Access Protocol (RDAP)
  • 7482 - Registration Data Access Protocol (RDAP) Query Format
  • 7483 - JSON Responses for the Registration Data Access Protocol (RDAP)
  • 7484 - Finding the Authoritative Registration Data (RDAP) Service

Also support the extensions:

  • NIC.br RDAP extension

Usage

Download the project with:

go get github.com/registrobr/rdap

And build a program like bellow for direct RDAP server requests:

package main

import (
	"encoding/json"
	"fmt"
	"url"

	"github.com/registrobr/rdap"
)

func main() {
	c := rdap.NewClient([]string{"https://rdap.beta.registro.br"})

	d, _, err := c.Query("nic.br", nil, nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	output, err := json.MarshalIndent(d, "", "  ")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(output))

	// Another example for a direct domain query adding a "ticket" parameter

	queryString := make(url.Values)
	queryString.Set("ticket", "5439886")

	d, _, err = c.Domain("rafael.net.br", nil, queryString)
	if err != nil {
		fmt.Println(err)
		return
	}

	output, err = json.MarshalIndent(d, "", "  ")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(output))
}

You can also try with bootstrap support:

package main

import (
	"encoding/json"
	"fmt"

	"github.com/registrobr/rdap"
)

func main() {
	c := rdap.NewClient(nil)

	ipnetwork, _, err := c.Query("214.1.2.3", nil, nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	output, err := json.MarshalIndent(ipnetwork, "", "  ")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(output))
}

For advanced users you probably want to reuse the HTTP client and add a cache layer:

package main

import (
	"encoding/json"
	"fmt"
	"net/http"

	"github.com/registrobr/rdap"
)

func main() {
	var httpClient http.Client

	cacheDetector := rdap.CacheDetector(func(resp *http.Response) bool {
		return resp.Header.Get("X-From-Cache") == "1"
	})

	c := rdap.Client{
		Transport: rdap.NewBootstrapFetcher(&httpClient, rdap.IANABootstrap, cacheDetector),
	}

	ipnetwork, _, err := c.Query("214.1.2.3", http.Header{
		"X-Forwarded-For": []string{"127.0.0.1"},
	}, nil)

	if err != nil {
		fmt.Println(err)
		return
	}

	output, err := json.MarshalIndent(ipnetwork, "", "  ")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(output))
}

An example of usage can be found in the project: https://github.com/registrobr/rdap-client