whois

package module
v0.0.0-...-cf81c24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 16 Imported by: 0

README

WHOIS Lookup Library

This library provides functionality for performing WHOIS lookups for domain names. It supports multiple TLD (Top Level Domain) adapters and can automatically detect the appropriate WHOIS server based on the domain name.

Installation

To install the library, use the following command:

go get -u github.com/joy4eg/whois

Usage

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/joy4eg/whois"
)

func main() {
    client, err := whois.New()
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    result, err := client.Whois(context.Background(), "example.com")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result)
}

Testing

go test ./...

Documentation

Overview

Package whois provides functionality for querying WHOIS information for domain names.

The package implements a WHOIS client that supports multiple TLD (Top Level Domain) adapters and can automatically detect the appropriate WHOIS server based on the domain name.

The client supports loading TLD configuration data from JSON files and provides flexible adapter options for different WHOIS server implementations.

Example usage:

client, err := whois.New()
if err != nil {
    log.Fatal(err)
}
result, err := client.Whois(context.Background(), "example.com")

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotMatchTLD = errors.New("cannot match TLD")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// Whois returns the result of a whois query for the given host.
	// The servers parameter is a list of whois servers to try in order, or nil to use the default list.
	// The result is the raw whois output.
	Whois(ctx context.Context, host string, servers ...string) (result string, err error)

	io.Closer
}

Client is a whois client.

func New

func New(opts ...Option) (Client, error)

New returns new whois client.

type Option

type Option func(*client)

Option is a client option.

func WithCache

func WithCache(ttl time.Duration) Option

type Record

type Record struct {
	// Domain name.
	Domain string `json:"domain"`

	// Domain creation date.
	CreatedDate time.Time `json:"created_date"`
}

Record is a whois record.

func ParseRecord

func ParseRecord(domain string, data []byte) (*Record, error)

ParseRecord parses raw WHOIS data for a given domain and returns a Record structure. It processes the raw byte data to extract domain information such as creation date.

Parameters:

  • domain: The domain name for which the WHOIS data is being parsed
  • data: Raw WHOIS response data as bytes

Returns:

  • *Record: A pointer to a Record structure containing the parsed information
  • error: An error if parsing fails, nil otherwise.

Directories

Path Synopsis
cmd
api command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL