### Complete RDAP Client Configuration Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md A comprehensive example demonstrating the configuration of the HTTP client, bootstrap client with disk caching, and the main RDAP client. It also shows creating a request with custom options and context. ```go package main import ( "context" "fmt" "log" "net/http" "net/url" "time" "github.com/openrdap/rdap" "github.com/openrdap/rdap/bootstrap" "github.com/openrdap/rdap/bootstrap/cache" ) func main() { // Configure HTTP client with custom timeouts and pool settings httpClient := &http.Client{ Timeout: 60 * time.Second, Transport: &http.Transport{ MaxIdleConns: 50, MaxIdleConnsPerHost: 10, MaxConnsPerHost: 10, }, } // Configure bootstrap with disk caching bootstrapClient := &bootstrap.Client{ HTTP: httpClient, BaseURL: mustParse("https://data.iana.org/rdap/"), Cache: cache.NewDiskCache(), Verbose: func(text string) { if text != "" { log.Printf("[Bootstrap] %s", text) } }, } // Configure main client client := &rdap.Client{ HTTP: httpClient, Bootstrap: bootstrapClient, UserAgent: "MyApp/1.0 (compatible with rdap)", Verbose: func(text string) { if text != "" { log.Printf("[RDAP] %s", text) } }, } // Create request with custom options req := &rdap.Request{ Type: rdap.DomainRequest, Query: "example.com", FetchRoles: []string{"registrant", "administrative"}, Timeout: 45 * time.Second, } // Add context with timeout ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() req = req.WithContext(ctx) // Execute request resp, err := client.Do(req) if err != nil { log.Fatalf("Query failed: %v", err) } // Process response if domain, ok := resp.Object.(*rdap.Domain); ok { fmt.Printf("Domain: %s\n", domain.LDHName) fmt.Printf("Handle: %s\n", domain.Handle) fmt.Printf("Status: %v\n", domain.Status) } } func mustParse(u string) *url.URL { parsed, _ := url.Parse(u) return parsed } ``` -------------------------------- ### Install OpenRDAP Client Source: https://github.com/openrdap/rdap/blob/master/README.md Installs the 'rdap' binary using Go. Ensure you have Go installed and configured. ```bash go install github.com/openrdap/rdap/cmd/rdap@master ``` -------------------------------- ### NewQuestion Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Demonstrates how to create a new bootstrap Question for a DNS registry query. ```go question := &bootstrap.Question{ RegistryType: bootstrap.DNS, Query: "example.com", } ``` -------------------------------- ### Question WithContext Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Shows how to create a copy of a Question with a specified context, useful for managing timeouts and cancellations. ```go ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) def cancel() question := question.WithContext(ctx) ``` -------------------------------- ### Answer Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Illustrates the structure of a bootstrap Answer, showing a resolved query, its entry, and associated RDAP URLs. ```go answer := &bootstrap.Answer{ Query: "example.com", Entry: "com", URLs: []*url.URL{ parsedURL1, // https://rdap.verisign.com/com/v1/ parsedURL2, }, } ``` -------------------------------- ### Example of RequestType.String() Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Demonstrates how to use the String() method to get a human-readable name for a RequestType. ```go req := &rdap.Request{Type: rdap.DomainRequest} fmt.Println(req.Type.String()) // Output: "domain" ``` -------------------------------- ### Example RDAP Output for an IP Address Source: https://github.com/openrdap/rdap/blob/master/README.md This snippet shows a partial example of the output received when querying an IP address using RDAP. It includes links to related resources, event information, and CIDR details. ```text Link: https://rdap.arin.net/registry/ip/8.8.8.0 Link: https://whois.arin.net/rest/net/NET-8-8-8-0-1 Link: https://rdap.arin.net/registry/ip/8.0.0.0/9 Event: Action: last changed Date: 2014-03-14T16:52:05-04:00 Event: Action: registration Date: 2014-03-14T16:52:05-04:00 cidr0_cidrs: v4prefix: 8.8.8.0 length: 24 ``` -------------------------------- ### Run OpenRDAP Client Source: https://github.com/openrdap/rdap/blob/master/README.md Executes the installed 'rdap' binary to query information for a domain. ```bash ~/go/bin/rdap google.com ``` -------------------------------- ### Query IP Network Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/rdap-objects.md Demonstrates how to query for IP network information using the RDAP client. Requires initializing the client and calling the QueryIP method. ```go client := &rdap.Client{} ipnet, err := client.QueryIP("192.0.2.0") if err != nil { log.Fatal(err) } fmt.Printf("Network: %s\n", ipnet.Name) ``` -------------------------------- ### Full RDAP Query and Response Handling Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/response.md Demonstrates a complete RDAP query process, including client initialization, request creation, response handling, and type assertion for domain or error objects. ```go client := &rdap.Client{} req := &rdap.Request{ Type: rdap.DomainRequest, Query: "example.com", } resp, err := client.Do(req) if err != nil { log.Fatal(err) } // Check HTTP response if len(resp.HTTP) > 0 && resp.HTTP[0].Error == nil { fmt.Printf("Status: %d\n", resp.HTTP[0].Response.StatusCode) } // Handle the RDAP object if domain, ok := resp.Object.(*rdap.Domain); ok { fmt.Printf("Domain: %s\n", domain.LDHName) fmt.Printf("Handle: %s\n", domain.Handle) fmt.Printf("Registrar: %s\n", domain.Port43) } else if err, ok := resp.Object.(*rdap.Error); ok { fmt.Printf("Server error: %s\n", err.Title) } ``` -------------------------------- ### Client Lookup Method Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Demonstrates how to use the Client's Lookup method to discover RDAP servers for a given query. It handles caching and returns a list of URLs or an error. ```go client := &bootstrap.Client{} question := &bootstrap.Question{ RegistryType: bootstrap.DNS, Query: "example.com", } answer, err := client.Lookup(question) if err != nil { log.Fatal(err) } for _, url := range answer.URLs { fmt.Println(url) } ``` -------------------------------- ### Complete RDAP Decoding Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/decoder.md Demonstrates how to create a client, decode JSON data into RDAP objects, and handle potential decoding errors, unknown fields, and warnings. ```go client := &rdap.Client{} // Create a custom decoder for fine-grained control jsonData := []byte(`{ "objectClassName": "domain", "rdapConformance": ["rdap_level_0"], "handle": "EXAMPLE.COM", "ldhName": "example.com", "entities": [], "unknownField": "unknown value" }`) decoder := rdap.NewDecoder(jsonData) obj, err := decoder.Decode() if err != nil { log.Fatal(err) } if domain, ok := obj.(*rdap.Domain); ok { // Check for decode errors allFields := domain.DecodeData.Fields() fmt.Printf("Total fields decoded: %d\n", len(allFields)) // Check for unknown fields unknown := domain.DecodeData.UnknownFields() for _, field := range unknown { value := domain.DecodeData.Value(field) fmt.Printf("Unknown field '%s' = %v\n", field, value) } // Check for decode warnings for _, field := range allFields { if notes := domain.DecodeData.Notes(field); len(notes) > 0 { fmt.Printf("Warnings for '%s': %v\n", field, notes) } } // Use the decoded domain fmt.Printf("Domain: %s\n", domain.LDHName) } ``` -------------------------------- ### Complete vCard Usage Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Demonstrates how to query domain information using the RDAP client and extract contact details from the associated vCard, including name, email, phone, fax, and address components. ```go client := &rdap.Client{} domain, err := client.QueryDomain("example.com") if err != nil { log.Fatal(err) } // Find the registrant entity var registrant *rdap.Entity for _, entity := range domain.Entities { for _, role := range entity.Roles { if role == "registrant" { registrant = &entity break } } } if registrant != nil && registrant.VCard != nil { vcard := registrant.VCard // Get contact information fmt.Printf("Name: %s\n", vcard.Name()) fmt.Printf("Email: %s\n", vcard.Email()) fmt.Printf("Phone: %s\n", vcard.Tel()) fmt.Printf("Fax: %s\n", vcard.Fax()) // Get address fmt.Printf("Address:\n") fmt.Printf(" Street: %s\n", vcard.StreetAddress()) fmt.Printf(" City: %s\n", vcard.Locality()) fmt.Printf(" State: %s\n", vcard.Region()) fmt.Printf(" ZIP: %s\n", vcard.PostalCode()) fmt.Printf(" Country: %s\n", vcard.Country()) } ``` -------------------------------- ### Converting Domain Response to WHOIS Style Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/response.md Example of converting an RDAP domain response to a WHOIS-style format and iterating through its data. ```go resp, _ := client.Do(req) whoisResp := resp.ToWhoisStyleResponse() for _, key := range whoisResp.KeyDisplayOrder { for _, value := range whoisResp.Data[key] { fmt.Printf("%s: %s\n", key, value) } } ``` -------------------------------- ### Access Specific Registry Objects Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Accessor methods to get specific registry objects after they have been downloaded. Returns nil if the registry has not yet been downloaded. ```go func (c *Client) DNS() *DNSRegistry func (c *Client) IPv4() *IPv4Registry func (c *Client) IPv6() *IPv6Registry func (c *Client) ASN() *ASNRegistry func (c *Client) ServiceProvider() *ServiceProviderRegistry ``` ```go client := &bootstrap.Client{} client.Download(bootstrap.DNS) dns := client.DNS() if dns != nil { // Access TLD entries for tld := range dns.File().Entries { fmt.Println(tld) } } ``` -------------------------------- ### Get Request Context Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md The Context method returns the context associated with the Request. It always returns a non-nil context, defaulting to context.Background() if none is explicitly set. ```go func (r *Request) Context() context.Context ``` -------------------------------- ### DNS, IPv4, IPv6, ASN, ServiceProvider Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Accessor methods to get registry objects. These methods return the corresponding registry object if it has been downloaded, otherwise nil. ```APIDOC ## DNS, IPv4, IPv6, ASN, ServiceProvider ### Description Accessor methods to get registry objects. ### Methods - **DNS()** (*DNSRegistry) - **IPv4()** (*IPv4Registry) - **IPv6()** (*IPv6Registry) - **ASN()** (*ASNRegistry) - **ServiceProvider()** (*ServiceProviderRegistry) ### Returns - Registry object (or nil if not yet downloaded) ### Example ```go client := &bootstrap.Client{} client.Download(bootstrap.DNS) dns := client.DNS() if dns != nil { // Access TLD entries for tld := range dns.File().Entries { fmt.Println(tld) } } ``` ``` -------------------------------- ### Handling NoWorkingServers Error Source: https://github.com/openrdap/rdap/blob/master/_autodocs/errors.md Provides an example of how to handle a NoWorkingServers error, which occurs when no RDAP servers respond successfully. It shows iterating through the HTTP errors to inspect individual server responses. ```Go resp, err := client.Do(req) if err != nil { fmt.Printf("Tried %d servers\n", len(resp.HTTP)) for i, http := range resp.HTTP { if http.Error != nil { fmt.Printf("Server %d error: %v\n", i, http.Error) } } } ``` -------------------------------- ### jCard JSON Format Example Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Illustrates the basic structure of a jCard, which is a JSON representation of vCard data according to RFC 7095. Shows common properties like version, name, telephone, email, address, and organization. ```json ["vcard", [ [ ["version", {}, "text", "4.0"], ["fn", {}, "text", "Jane Doe"], ["tel", {"type":["work", "voice"]}, "uri", "tel:+1-555-555-5555"], ["email", {}, "text", "jane@example.com"], ["adr", {}, "text", ["", "", "123 Main St", "Anytown", "ST", "12345", "USA"]], ["org", {}, "text", "Example Corp"] ] ]] ``` -------------------------------- ### Configure Bootstrap Client with Custom Settings Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Set up a custom bootstrap client, specifying the HTTP client, base URL for service registry files, a memory cache, and a verbose logging callback. ```go client := &rdap.Client{ Bootstrap: &bootstrap.Client{ HTTP: &http.Client{}, BaseURL: mustParse("https://data.iana.org/rdap/"), Cache: cache.NewMemoryCache(), Verbose: func(text string) { log.Println(text) }, }, } ``` -------------------------------- ### Get VCardProperty String Representation Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns a human-readable string representation of a VCardProperty. This is useful for debugging or display purposes. ```go func (p *VCardProperty) String() string ``` -------------------------------- ### Get Locality (City) Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the locality (city) component of a vCard address. Returns an empty string if not present. ```go func (v *VCard) Locality() string ``` -------------------------------- ### Get Street Address Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the street address component of a vCard address. Returns an empty string if not present. ```go func (v *VCard) StreetAddress() string ``` -------------------------------- ### Import Paths for OpenRDAP Source: https://github.com/openrdap/rdap/blob/master/_autodocs/README.md Import the main OpenRDAP package, the bootstrap package for server discovery, and caching backends for bootstrap. ```go import "github.com/openrdap/rdap" import "github.com/openrdap/rdap/bootstrap" import "github.com/openrdap/rdap/bootstrap/cache" ``` -------------------------------- ### Configure RDAP Client for Low-Resource Environments Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Use minimal HTTP pooling and a memory cache for environments with limited resources to reduce memory footprint and I/O. ```go // Minimal HTTP pooling client := &rdap.Client{ HTTP: &http.Client{ Timeout: 30 * time.Second, Transport: &http.Transport{ MaxIdleConns: 2, }, }, } // Memory cache (no disk I/O) client.Bootstrap = &bootstrap.Client{ Cache: cache.NewMemoryCache(), } ``` -------------------------------- ### Get VCardProperty Values as Strings Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves all values of a VCardProperty, flattened into a slice of strings. Useful for properties that can have multiple values. ```go func (p *VCardProperty) Values() []string ``` ```go emailProp := vcard.GetFirst("email") if emailProp != nil { emails := emailProp.Values() for _, email := range emails { fmt.Println(email) } } ``` -------------------------------- ### Get Country Name Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the full country name component of a vCard address. Returns an empty string if not present. ```go func (v *VCard) Country() string ``` -------------------------------- ### Automatic Bootstrap Client Usage with RDAP Client Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Demonstrates how the RDAP client automatically uses the bootstrap client for server discovery for queries that support bootstrapping. For queries that do not support bootstrapping, the server must be explicitly specified. ```go client := &rdap.Client{} ``` ```go // For queries that support bootstrapping (Domain, IP, Autnum), // the client automatically uses bootstrap domain, err := client.QueryDomain("example.com") ``` ```go // For queries that don't support bootstrapping, specify the server server, _ := url.Parse("https://rdap.nic.cz") req := &rdap.Request{ Type: rdap.NameserverRequest, Query: "ns1.example.com", Server: server, } resp, err := client.Do(req) ``` -------------------------------- ### Initialize Bootstrap Client with Custom Disk Cache Path Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Specify a custom directory for the disk cache when initializing the bootstrap client, allowing for flexible storage location. ```go client := &bootstrap.Client{ Cache: cache.NewDiskCacheWithPath("/custom/cache/path"), } ``` -------------------------------- ### Get Region (State/Province) Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the region (state or province) component of a vCard address. Returns an empty string if not present. ```go func (v *VCard) Region() string ``` -------------------------------- ### Initialize Bootstrap Client with Disk Cache Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Configure the bootstrap client to use a disk cache for persistence across process restarts and sharing between processes. Ensure the cache directory is writable. ```go import "github.com/openrdap/rdap/bootstrap/cache" client := &bootstrap.Client{ Cache: cache.NewDiskCache(), } ``` -------------------------------- ### Get VCard Name Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves the primary name (fn property) of the vCard. Returns an empty string if no name is present. ```go func (v *VCard) Name() string ``` ```go fmt.Println(vcard.Name()) // Output: John Doe ``` -------------------------------- ### Get POBox Address Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the PO Box component of a vCard address. Returns an empty string if no PO Box is present. ```go func (v *VCard) POBox() string ``` -------------------------------- ### Get VCard Organization Name Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves the organization name (org property) from the vCard. Returns an empty string if no organization is present. ```go func (v *VCard) Org() string ``` -------------------------------- ### Initialize Bootstrap Client with Memory Cache Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Use the default memory cache for the bootstrap client, which provides fast lookups but loses data when the process exits. ```go client := &bootstrap.Client{ Cache: cache.NewMemoryCache(), } ``` -------------------------------- ### Get VCard Email Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves the primary email address (email property) of the vCard. Returns an empty string if no email is present. ```go func (v *VCard) Email() string ``` -------------------------------- ### Configure X.509 Client Authentication Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Set up TLS client authentication using X.509 certificates by configuring the HTTP client's TLSClientConfig with loaded key pairs. ```go cert, err := tls.LoadX509KeyPair("cert.pem", "key.pem") if err != nil { log.Fatal(err) } client := &rdap.Client{ HTTP: &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ Certificates: []tls.Certificate{cert}, }, }, }, } ``` -------------------------------- ### Get VCard Properties by Name Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves all vCard properties that match the specified name. Returns an empty slice if no properties are found. ```go func (v *VCard) Get(name string) []*VCardProperty ``` ```go phones := vcard.Get("tel") for _, phone := range phones { fmt.Println(phone.Values()) } ``` -------------------------------- ### Handle Query Timeouts with Context Source: https://github.com/openrdap/rdap/blob/master/_autodocs/errors.md Illustrates how to implement query timeouts using Go's context package, checking if the error is due to a deadline exceeded. ```go ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) def cancel() req := req.WithContext(ctx) resp, err := client.Do(req) if err != nil && ctx.Err() == context.DeadlineExceeded { fmt.Println("Query timed out") } ``` -------------------------------- ### Get Notes for a Field Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/decoder.md Retrieves a list of minor errors or warnings associated with a specific RDAP field. Useful for validating decoded data. ```go func (r DecodeData) Notes(name string) []string ``` ```go // Check for decode errors on a field if notes := domain.DecodeData.Notes("handle"); len(notes) > 0 { fmt.Printf("Errors decoding 'handle' field: %v\n", notes) } ``` -------------------------------- ### Get Postal Code (ZIP) Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the postal code (zip code) component of a vCard address. Returns an empty string if not present. ```go func (v *VCard) PostalCode() string ``` -------------------------------- ### Handling BootstrapNotSupported Error Source: https://github.com/openrdap/rdap/blob/master/_autodocs/errors.md Shows how to construct a request that would trigger a BootstrapNotSupported error and how to fix it by specifying the server for bootstrapping-unsupported query types like Help. ```Go req := &rdap.Request{ Type: rdap.HelpRequest, Query: "", // Help doesn't support bootstrapping // Server is required for Help queries } // Returns BootstrapNotSupported if Server is nil // Fix: Specify the server req.Server, _ = url.Parse("https://rdap.example.com") ``` -------------------------------- ### Get Extended Address Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Returns the extended address component (e.g., apartment or suite number) of a vCard address. Returns an empty string if not present. ```go func (v *VCard) ExtendedAddress() string ``` -------------------------------- ### Create a New Help Request Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Use NewHelpRequest to create a new Request object specifically for help queries. The RDAP server must be specified separately. ```go func NewHelpRequest() *Request ``` -------------------------------- ### Get First VCard Property by Name Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves the first vCard property that matches the specified name. Returns nil if no matching property is found. ```go func (v *VCard) GetFirst(name string) *VCardProperty ``` -------------------------------- ### DownloadWithContext Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Forces a download of a Service Registry file with context support. ```APIDOC ## DownloadWithContext ### Description Forces a download with context support. ### Method ```go func (c *Client) DownloadWithContext(ctx context.Context, registryType RegistryType) error ``` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - The context for the download operation. - **registryType** (RegistryType) - Required - Registry type to download ### Returns - error ``` -------------------------------- ### Perform Search Queries Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Execute search queries for domains or entities using wildcard patterns. A server must be specified for search requests. ```Go // Domain search req := &rdap.Request{ Type: rdap.DomainSearchRequest, Query: "example*.com", } req = req.WithServer(server) // Server required for searches // Entity search req := &rdap.Request{ Type: rdap.EntitySearchRequest, Query: "ABC*", } req = req.WithServer(server) ``` -------------------------------- ### Add Custom Query Parameters Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Customize RDAP requests by adding parameters to the Params field of the rdap.Request struct. This example adds a 'cursor' parameter for pagination. ```go req := &rdap.Request{ Type: rdap.DomainSearchRequest, Query: "example*.com", Params: url.Values{ "cursor": {"0"}, }, } ``` -------------------------------- ### Query Help Information with Specific Server Source: https://github.com/openrdap/rdap/blob/master/README.md Performs a verbose query for help information, explicitly specifying the RDAP server URL. ```bash rdap -v -t help -s https://rdap.verisign.com/com/v1 ``` -------------------------------- ### Get VCard Fax Number Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves the first fax number (tel property with type=fax) from the vCard. Returns an empty string if no fax number is present. ```go func (v *VCard) Fax() string ``` -------------------------------- ### Download Service Registry File with Context Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Forces a download of a specified Service Registry file with context support. This is useful for managing request timeouts and cancellations. ```go func (c *Client) DownloadWithContext(ctx context.Context, registryType RegistryType) error ``` -------------------------------- ### RDAP Domain Information for EXAMPLE.COM Source: https://github.com/openrdap/rdap/blob/master/README.md This snippet shows the RDAP response for the domain EXAMPLE.COM, including its status, registration events, and secure DNS information. ```text Domain: Domain Name: EXAMPLE.COM Handle: 2336799_DOMAIN_COM-VRSN Status: client delete prohibited Status: client transfer prohibited Status: client update prohibited Conformance: rdap_level_0 Conformance: icann_rdap_technical_implementation_guide_0 Conformance: icann_rdap_response_profile_0 Notice: Title: Terms of Use Description: Service subject to Terms of Use. Link: https://www.verisign.com/domain-names/registration-data-access-protocol/terms-service/index.xhtml Notice: Title: Status Codes Description: For more information on domain status codes, please visit https://icann.org/epp Link: https://icann.org/epp Notice: Title: RDDS Inaccuracy Complaint Form Description: URL of the ICANN RDDS Inaccuracy Complaint Form: https://icann.org/wicf Link: https://icann.org/wicf Link: https://rdap.verisign.com/com/v1/domain/EXAMPLE.COM Event: Action: registration Date: 1995-08-14T04:00:00Z Event: Action: expiration Date: 2023-08-13T04:00:00Z Event: Action: last changed Date: 2023-05-12T15:13:35Z Event: Action: last update of RDAP database Date: 2023-05-16T20:36:06Z Secure DNS: Delegation Signed: true DSData: Key Tag: 370 Algorithm: 13 Digest: BE74359954660069D5C63D200C39F5603827D7DD02B56F120EE9F3A86764247C DigestType: 2 Entity: Handle: 376 Public ID: Type: IANA Registrar ID Identifier: 376 Role: registrar vCard version: 4.0 vCard fn: RESERVED-Internet Assigned Numbers Authority Entity: Role: abuse vCard version: 4.0 Nameserver: Nameserver: A.IANA-SERVERS.NET Nameserver: Nameserver: B.IANA-SERVERS.NET ``` -------------------------------- ### Configure RDAP Client for High-Volume Queries Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Increase HTTP connection pooling and use disk cache for bootstrap to handle high volumes efficiently and avoid network hits. ```go // Increase HTTP connection pooling client := &rdap.Client{ HTTP: &http.Client{ Transport: &http.Transport{ MaxIdleConns: 200, MaxIdleConnsPerHost: 50, MaxConnsPerHost: 50, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).DialContext, }, }, } // Use disk cache for bootstrap to avoid network hits client.Bootstrap = &bootstrap.Client{ Cache: cache.NewDiskCache(), } ``` -------------------------------- ### Simple Domain Query Source: https://github.com/openrdap/rdap/blob/master/_autodocs/README.md Perform a basic query for domain registration data. This method returns the domain object and any potential error. A default timeout of 30 seconds is applied. ```go client := &rdap.Client{} domain, err := client.QueryDomain("example.com") // Returns: (*Domain, error) // Timeout: 30 seconds ``` -------------------------------- ### Create a Request Copy with Server Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Use WithServer to create a copy of the Request with a different RDAP server URL. This allows you to easily switch the target server for a request. ```go server, _ := url.Parse("https://rdap.verisign.com") req2 := req.WithServer(server) ``` -------------------------------- ### Get VCard Voice Telephone Number Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Retrieves the first voice telephone number (tel property with type=voice) from the vCard. Returns an empty string if no voice number is present. ```go func (v *VCard) Tel() string ``` -------------------------------- ### CLI: Custom Bootstrap URL and Cache TTL Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Configure a custom bootstrap URL with --bs-url and set the bootstrap cache Time-To-Live (TTL) in seconds using --bs-ttl. ```bash # Custom bootstrap URL rdap --bs-url=https://custom-registry.example.com example.com # Bootstrap cache TTL in seconds rdap --bs-ttl=7200 example.com ``` -------------------------------- ### WithServer Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Returns a copy of the Request with an updated RDAP server URL. ```APIDOC ## WithServer ### Description Returns a new Request object that is a copy of the original but configured with a different RDAP server URL. This allows you to easily switch the target server for a request. ### Method ```go func (r *Request) WithServer(server *url.URL) *Request ``` ### Parameters #### Path Parameters - **server** (*url.URL) - Required - The RDAP server URL to set for the new Request. ### Returns *Request - A copy of the Request with the updated server URL. ### Example ```go import ( "net/url" "github.com/rdap/rdap" ) // Assume 'req' is an existing *rdap.Request object server, _ := url.Parse("https://rdap.verisign.com") newReq := req.WithServer(server) ``` ``` -------------------------------- ### NewNameserverRequest Constructor Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Creates a new RDAP Request specifically for querying a nameserver. Requires the RDAP server to be specified separately. ```go func NewNameserverRequest(nameserver string) *Request ``` -------------------------------- ### Query Domain Information Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Use this snippet to retrieve basic information about a domain name. It requires importing the 'fmt', 'log', and 'github.com/openrdap/rdap' packages. ```Go package main import ( "fmt" "log" "github.com/openrdap/rdap" ) func main() { client := &rdap.Client{} domain, err := client.QueryDomain("example.com") if err != nil { log.Fatal(err) } fmt.Printf("Domain: %s\n", domain.LDHName) fmt.Printf("Handle: %s\n", domain.Handle) fmt.Printf("Status: %v\n", domain.Status) } ``` -------------------------------- ### Fetch Full Contact Information with Specific Roles Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Request a domain object while explicitly fetching contact information for specific roles like 'registrant', 'administrative', or 'billing'. This ensures full contact details are returned instead of just URLs. ```Go req := &rdap.Request{ Type: rdap.DomainRequest, Query: "example.com", FetchRoles: []string{"registrant", "administrative", "billing"}, } resp, _ := client.Do(req) // Entities will have full contact info instead of just URLs ``` -------------------------------- ### Get decoded field names Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/decoder.md Returns a list of all RDAP field names that were decoded. Field names are in RDAP format (e.g., "port43"), not Go format (e.g., "Port43"). ```go domain, _ := client.QueryDomain("example.com") fields := domain.DecodeData.Fields() for _, field := range fields { fmt.Println(field) } ``` -------------------------------- ### Configure Request to Fetch Additional Roles Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Set the FetchRoles field to specify which additional contact information roles (e.g., 'registrant', 'administrative') should be fetched. Use 'all' to fetch all available roles. ```go req := &rdap.Request{ Type: rdap.DomainRequest, Query: "example.com", FetchRoles: []string{"registrant", "administrative"}, } ``` -------------------------------- ### Get raw field value Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/decoder.md Returns the raw value of a specified RDAP field. Field names are in RDAP format (e.g., "port43"), not Go format (e.g., "Port43"). Returns nil if the field is not found. ```go // Access an unknown field customValue := domain.DecodeData.Value("customField") if customValue != nil { fmt.Printf("Custom field value: %v\n", customValue) } // Access a known field by RDAP name port43 := domain.DecodeData.Value("port43") ``` -------------------------------- ### Advanced Domain Query with Options Source: https://github.com/openrdap/rdap/blob/master/_autodocs/README.md Construct a detailed request for domain information, allowing customization of the query type, server, fetch roles, and timeout. Context can also be added for cancellation or deadlines. ```go req := &rdap.Request{ Type: rdap.DomainRequest, Query: "example.com", Server: server, // Optional: override server FetchRoles: []string{"all"}, // Optional: fetch contact info Timeout: 45 * time.Second, // Optional: custom timeout } req = req.WithContext(ctx) // Optional: add context resp, err := client.Do(req) // Returns: (*Response, error) // Response.Object is one of: Domain, Autnum, IPNetwork, Entity, Nameserver, Error, Help, SearchResults ``` -------------------------------- ### CLI: Request Timeout and Authentication Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Set the request timeout in seconds using the --timeout flag. Configure X.509 authentication using .p12 files or separate certificate and key files. ```bash # Timeout in seconds rdap --timeout=45 example.com # X.509 authentication rdap --p12=cert.p12 example.com rdap --p12=cert.p12:password example.com rdap -C cert.pem -K key.pem example.com ``` -------------------------------- ### Make Raw RDAP URL Request Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Construct and execute a request directly using a full RDAP URL, bypassing the structured query methods. Requires 'net/url' package. ```Go rdapURL, _ := url.Parse("https://rdap.example.com/domain/example.com") req := rdap.NewRawRequest(rdapURL) resp, _ := client.Do(req) ``` -------------------------------- ### Help Struct Definition Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/rdap-objects.md Defines the structure for RDAP help responses. Includes common fields and notices. ```go type Help struct { DecodeData *DecodeData Common Conformance []string Notices []Notice } ``` -------------------------------- ### Client Type Definition Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Defines the structure of the bootstrap Client, including its HTTP client, base URL, cache, and verbose logging callback. ```go type Client struct { HTTP *http.Client BaseURL *url.URL Cache cache.RegistryCache Verbose func(text string) registries map[RegistryType]Registry } ``` -------------------------------- ### Manage Request Context with Timeout Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Use context.WithTimeout to set a deadline for requests. Ensure to call cancel to release resources. Check ctx.Err() for DeadlineExceeded. ```go ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) def cancel() req := req.WithContext(ctx) resp, err := client.Do(req) if err != nil && ctx.Err() == context.DeadlineExceeded { fmt.Println("Request timed out") } ``` -------------------------------- ### NewHelpRequest Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Creates a new Request object specifically for help queries. The RDAP server must be specified separately. ```APIDOC ## NewHelpRequest ### Description Creates a new Request object with the type set to HelpRequest. The RDAP server must be specified using `WithServer` or by setting the `Server` field directly. ### Method ```go func NewHelpRequest() *Request ``` ### Returns *Request - A new Request object with Type set to HelpRequest. ``` -------------------------------- ### Create a Request Copy with Context Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Use WithContext to create a copy of the Request with an associated context. This is useful for managing request timeouts and cancellations. ```go ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) deffer cancel() req := req.WithContext(ctx) ``` -------------------------------- ### Configure Bootstrap Client with Disk Caching Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Configures the bootstrap client to use disk caching instead of the default in-memory caching. Disk caching persists registry data to disk, which is loaded on subsequent calls until the cache expires. ```go import "github.com/openrdap/rdap/bootstrap/cache" ``` ```go client := &bootstrap.Client{} client.Cache = cache.NewDiskCache() // First call downloads and caches to disk client.Download(bootstrap.DNS) // Subsequent calls load from disk until cache expires (24h default) client.Download(bootstrap.DNS) ``` -------------------------------- ### Use a Custom HTTP Client Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Integrate a custom 'http.Client' with specific configurations, such as timeouts or transport settings, into the RDAP client. Requires 'net/http' and 'time' packages. ```Go httpClient := &http.Client{ Timeout: 60 * time.Second, Transport: &http.Transport{ MaxIdleConns: 50, }, } client := &rdap.Client{ HTTP: httpClient, } ``` -------------------------------- ### Handling ObjectDoesNotExist Error Source: https://github.com/openrdap/rdap/blob/master/_autodocs/errors.md Demonstrates how to specifically check for and handle the ObjectDoesNotExist error, which corresponds to an HTTP 404 response from the RDAP server, indicating the requested object is not found. ```Go domain, err := client.QueryDomain("nonexistent-domain-9999.com") if ce, ok := err.(*rdap.ClientError); ok && ce.Type == rdap.ObjectDoesNotExist { fmt.Println("Domain not found in registry") } ``` -------------------------------- ### Configure RDAP Client with Client Certificates Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Configure the RDAP client to use client certificates for authentication when required by RDAP servers. ```go cert, _ := tls.LoadX509KeyPair("client-cert.pem", "client-key.pem") client := &rdap.Client{ HTTP: &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ Certificates: []tls.Certificate{cert}, }, }, }, } ``` -------------------------------- ### Configure Custom Bootstrap Service URL Source: https://github.com/openrdap/rdap/blob/master/_autodocs/configuration.md Override the default IANA service URL by providing a custom URL to the bootstrap.Client. This allows using alternative RDAP data sources. ```go baseURL, _ := url.Parse("https://custom-rdap-registry.example.com/") client := &bootstrap.Client{ BaseURL: baseURL, } ``` -------------------------------- ### Enable Verbose Logging Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Configure the RDAP client to output verbose logging information to standard error. This is useful for debugging communication with RDAP servers. Requires 'os' package. ```Go client := &rdap.Client{ Verbose: func(text string) { if text != "" { fmt.Fprintf(os.Stderr, "[RDAP] %s\n", text) } }, } ``` -------------------------------- ### Download Service Registry File Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Forces a download of a specified Service Registry file. Use this when you need to ensure the latest registry data is available. ```go func (c *Client) Download(registryType RegistryType) error ``` ```go client := &bootstrap.Client{} err := client.Download(bootstrap.DNS) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Data Flow Visualization Source: https://github.com/openrdap/rdap/blob/master/_autodocs/README.md Illustrates the sequence of operations when a user query is processed by the RDAP client. It shows request construction, potential bootstrapping for server discovery, HTTP communication, and JSON response decoding. ```text User Query ↓ Request Construction (Domain, IP, etc.) ↓ Client.Do(Request) ├─ Validate Request ├─ Bootstrap (if no Server specified) │ └─ Query IANA Service Registry ├─ HTTP GET to RDAP server ├─ Decode JSON response └─ Return Response ├─ Response.Object (Domain, IPNetwork, etc.) ├─ Response.HTTP (HTTP response details) └─ Response.BootstrapAnswer (server info) ``` -------------------------------- ### Bootstrap Server Discovery Source: https://github.com/openrdap/rdap/blob/master/_autodocs/INDEX.md The bootstrap package aids in discovering RDAP servers. It allows for querying bootstrap information for various registry types and supports caching of discovered server information. ```APIDOC ## Bootstrap Server Discovery ### Description The `bootstrap` package assists in the discovery of RDAP servers, enabling the client to find the appropriate server for a given query without hardcoding endpoints. It supports different registry types and provides mechanisms for caching discovered server information to improve performance. ### Types - **Client**: The main client for bootstrap lookups. - **Question**: Represents a bootstrap query. - **Answer**: Represents the result of a bootstrap query. - **RegistryType**: An enumeration for different types of registries (e.g., DNS, IPv4, ASN). ### Methods - **Lookup(q bootstrap.Question)**: Performs a lookup for the given bootstrap question. - **Download()**: Downloads bootstrap data from a source. ### Configuration - **Caching**: Supports configurable caching mechanisms (Memory, Disk) for bootstrap data. ``` -------------------------------- ### NewVCardWithOptions Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Creates a VCard object from a JSON blob with customizable decoder options. This allows for more control over the decoding process, such as ignoring invalid properties. ```APIDOC ## NewVCardWithOptions ### Description Creates a VCard with custom decoder options. ### Method ```go func NewVCardWithOptions(jsonBlob []byte, options VCardOptions) (*VCard, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go vcard, err := rdap.NewVCardWithOptions(jsonData, rdap.VCardOptions{ IgnoreInvalidProperties: true, }) ``` ### Response #### Success Response (200) * **VCard** (*VCard) - A pointer to the created VCard object. * **error** (error) - An error if the JSON data is invalid or cannot be parsed. #### Response Example ```json // VCard object representing the parsed contact information ``` **Source:** `vcard.go:159-171` ``` -------------------------------- ### Handling Client Errors in Go Source: https://github.com/openrdap/rdap/blob/master/_autodocs/errors.md Demonstrates how to check for and extract specific client error details when an RDAP operation fails. This is useful for differentiating between various client-side issues. ```Go resp, err := client.Do(req) if err != nil { if ce, ok := err.(*rdap.ClientError); ok { fmt.Printf("Error type: %d\n", ce.Type) fmt.Printf("Error message: %s\n", ce.Text) } } ``` -------------------------------- ### Implement Disk Cache for Bootstrap Data Source: https://github.com/openrdap/rdap/blob/master/_autodocs/quick-start.md Configure the RDAP client to use a disk-based cache for bootstrap information, improving performance by reducing repeated network lookups for service discovery. Requires importing 'github.com/openrdap/rdap/bootstrap/cache'. ```Go import "github.com/openrdap/rdap/bootstrap/cache" client := &rdap.Client{ Bootstrap: &bootstrap.Client{ Cache: cache.NewDiskCache(), }, } ``` -------------------------------- ### Create VCard with Custom Decoder Options Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/vcard.md Creates a VCard from JSON data using specified decoder options. Useful for controlling how invalid properties are handled during decoding. ```go func NewVCardWithOptions(jsonBlob []byte, options VCardOptions) (*VCard, error) ``` ```go vcard, err := rdap.NewVCardWithOptions(jsonData, rdap.VCardOptions{ IgnoreInvalidProperties: true, }) ``` -------------------------------- ### Question Type Definition Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/bootstrap.md Defines the structure for a bootstrap query, including the registry type, query string, and context. ```go type Question struct { RegistryType Query string ctx context.Context } ``` -------------------------------- ### Nameserver Struct Definition Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/rdap-objects.md Defines the structure for DNS nameserver information. Includes fields for hostname, associated IP addresses, and entities. ```go type Nameserver struct { DecodeData *DecodeData Common Conformance []string ObjectClassName string Notices []Notice Handle string LDHName string UnicodeName string IPAddresses *IPAddressSet Entities []Entity Status []string Remarks []Remark Links []Link Port43 string Events []Event } ``` -------------------------------- ### NewNameserverRequest Source: https://github.com/openrdap/rdap/blob/master/_autodocs/api-reference/request.md Creates a new Request for a nameserver query. Note that the RDAP server must be specified when using this constructor. ```APIDOC ## NewNameserverRequest ### Description Creates a new Request for a nameserver query. ### Method ```go func NewNameserverRequest(nameserver string) *Request ``` ### Parameters #### Path Parameters - **nameserver** (string) - Yes - Nameserver name ### Returns *Request with Type=NameserverRequest ### Note The RDAP server must be specified. ### Example ```go req := rdap.NewNameserverRequest("example.com") ``` ``` -------------------------------- ### Handling BootstrapNoMatch Error Source: https://github.com/openrdap/rdap/blob/master/_autodocs/errors.md Demonstrates a scenario that might lead to a BootstrapNoMatch error, which occurs when no RDAP servers are found for a given query. It also shows how to resolve this by using a valid TLD. ```Go // For a TLD without RDAP support domain, err := client.QueryDomain("example.test") // May return BootstrapNoMatch // Fix: Use a supported TLD domain, err := client.QueryDomain("example.com") ``` -------------------------------- ### Configuration Options Source: https://github.com/openrdap/rdap/blob/master/_autodocs/INDEX.md Describes the various configuration options for the RDAP client, including HTTP client tuning, caching, and security settings. ```APIDOC ## Client Configuration This section outlines the configuration options available for the RDAP client. ### `Client` Struct Configuration - **HTTP Client Tuning**: Options to configure the underlying HTTP client (e.g., timeouts, connection pooling). - **Bootstrap Configuration**: Settings for server discovery, including cache options. - **Request Configuration**: Parameters that can be set per request. - **Cache Options**: Configuration for caching mechanisms (memory vs. disk). - **TLS Client Authentication**: Settings for mutual TLS authentication. ### Performance Tuning Guidelines and options for optimizing client performance. ### Security Considerations Important security aspects to consider when configuring the client. ### CLI Flags and Environment Variables Details on how to configure the client using command-line flags and environment variables. A complete configuration example is provided in the `configuration.md` file. ```