Documentation
¶
Overview ¶
Package whodis provides protocol-aware registration-data lookups.
Its public API intentionally has no terminal or GUI dependency, so the same Client can power the command-line tool, native desktop app, and other clients.
Index ¶
- func Render(writer io.Writer, result LookupResult, format Format, options RenderOptions) error
- func RenderBatch(writer io.Writer, batch BatchResult, format Format, options BatchRenderOptions) error
- type BatchError
- type BatchItem
- type BatchLookupOptions
- type BatchProgress
- type BatchRenderOptions
- type BatchResult
- type Client
- func (c *Client) Lookup(ctx context.Context, input string, options LookupOptions) (LookupResult, error)
- func (c *Client) LookupBatch(ctx context.Context, inputs []string, options BatchLookupOptions) (BatchResult, error)
- func (c *Client) Route(ctx context.Context, input string, options LookupOptions) (RouteDecision, error)
- type ClientOptions
- type DNSMode
- type DNSRecord
- type DNSResult
- type Entity
- type ErrorKind
- type Event
- type FallbackMode
- type Format
- type Kind
- type LookupError
- type LookupOptions
- type LookupResult
- type Notice
- type Object
- type ProjectionField
- type Protocol
- type ProtocolAdapter
- type RenderOptions
- type RouteDecision
- type Source
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
func Render(writer io.Writer, result LookupResult, format Format, options RenderOptions) error
Render writes one successful result in the requested format.
func RenderBatch ¶ added in v0.6.0
func RenderBatch(writer io.Writer, batch BatchResult, format Format, options BatchRenderOptions) error
RenderBatch writes a completed batch. Empty Fields preserves complete registration results; non-empty Fields activates the compact projection.
Types ¶
type BatchError ¶ added in v0.6.0
type BatchError struct {
Kind ErrorKind `json:"kind" yaml:"kind"`
Message string `json:"message" yaml:"message"`
}
BatchError is the safe-to-serialize form of a lookup failure.
type BatchItem ¶ added in v0.6.0
type BatchItem struct {
Input string `json:"input" yaml:"input"`
Result *LookupResult `json:"result,omitempty" yaml:"result,omitempty"`
Error *BatchError `json:"error,omitempty" yaml:"error,omitempty"`
}
BatchItem retains the original input so an invalid target and a successful canonicalized target can be displayed together without losing attribution. Exactly one of Result and Error is set after LookupBatch completes.
type BatchLookupOptions ¶ added in v0.6.0
type BatchLookupOptions struct {
LookupOptions LookupOptions
Workers int
// OnProgress is called once for each completed item. Calls are serialized
// in completion order and never overlap. The callback may be nil.
OnProgress func(BatchProgress)
}
BatchLookupOptions controls a concurrent group of independent lookups. Workers defaults to four when it is zero. Per-item lookup errors are returned in BatchResult rather than stopping the rest of the batch.
type BatchProgress ¶ added in v0.6.0
BatchProgress describes one completed item in an active batch lookup. Index is the item's original input position, while Completed counts all items completed so far regardless of input order.
type BatchRenderOptions ¶ added in v0.6.0
type BatchRenderOptions struct {
RenderOptions
Fields []ProjectionField
}
BatchRenderOptions controls rendering of batch results. Fields selects the compact projection mode; an empty list renders complete lookup results.
type BatchResult ¶ added in v0.6.0
type BatchResult struct {
SchemaVersion int `json:"schema_version" yaml:"schema_version"`
Items []BatchItem `json:"items" yaml:"items"`
}
BatchResult is the serializable response returned by Client.LookupBatch. Embedded LookupResult values retain their own schema version.
func (BatchResult) HasErrors ¶ added in v0.6.0
func (r BatchResult) HasErrors() bool
HasErrors reports whether any item in the completed batch failed.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is safe to reuse for multiple sequential or concurrent lookups.
func NewClient ¶
func NewClient(options ClientOptions) *Client
NewClient creates a protocol-aware lookup client. It makes no network requests until Route or Lookup is called.
func (*Client) Lookup ¶
func (c *Client) Lookup(ctx context.Context, input string, options LookupOptions) (LookupResult, error)
Lookup resolves one target and returns a stable, renderer-independent model.
func (*Client) LookupBatch ¶ added in v0.6.0
func (c *Client) LookupBatch(ctx context.Context, inputs []string, options BatchLookupOptions) (BatchResult, error)
LookupBatch resolves each input independently with bounded concurrency. It preserves order and duplicates, and records an error on the affected item rather than failing the entire operation.
func (*Client) Route ¶
func (c *Client) Route(ctx context.Context, input string, options LookupOptions) (RouteDecision, error)
Route decides which known authority should receive a lookup without making a registration-data query. WHOIS route discovery may query IANA's referral service when the selected protocol is WHOIS.
type ClientOptions ¶
type ClientOptions struct {
Timeout time.Duration
CacheDirectory string
Adapters []ProtocolAdapter
}
ClientOptions configures a reusable lookup client.
type DNSMode ¶ added in v0.5.0
type DNSMode string
DNSMode controls optional DNS enrichment for a lookup. A zero-value LookupOptions leaves DNS disabled; DNSAuto remains available for callers that want domain-only discovery without special-casing non-domain targets.
type DNSRecord ¶ added in v0.5.0
type DNSRecord struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
TTL uint32 `json:"ttl" yaml:"ttl"`
Value string `json:"value" yaml:"value"`
}
DNSRecord is one public DNS resource record. Value is canonical DNS RDATA text, suitable for display and zone-file-oriented export.
type DNSResult ¶ added in v0.5.0
type DNSResult struct {
Method string `json:"method" yaml:"method"`
Complete bool `json:"complete" yaml:"complete"`
Nameservers []string `json:"nameservers,omitempty" yaml:"nameservers,omitempty"`
Records []DNSRecord `json:"records,omitempty" yaml:"records,omitempty"`
Warnings []string `json:"warnings,omitempty" yaml:"warnings,omitempty"`
}
DNSResult records records discovered alongside registration data. Complete is true only when an untruncated authoritative AXFR completed successfully. Pattern scans intentionally remain incomplete: DNS has no reliable general mechanism to enumerate arbitrary owner names in a zone.
type Entity ¶
type Entity struct {
Roles []string `json:"roles,omitempty" yaml:"roles,omitempty"`
Handle string `json:"handle,omitempty" yaml:"handle,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Organization string `json:"organization,omitempty" yaml:"organization,omitempty"`
Email string `json:"email,omitempty" yaml:"email,omitempty"`
Phone string `json:"phone,omitempty" yaml:"phone,omitempty"`
}
Entity contains public contact or organization information. Fields that are redacted by a registry remain absent rather than being invented.
type ErrorKind ¶
type ErrorKind string
ErrorKind allows command-line callers and future UIs to handle lookup failures without string matching.
type Event ¶
type Event struct {
Action string `json:"action" yaml:"action"`
Date string `json:"date" yaml:"date"`
}
Event is a dated registration event such as registration or expiration.
type FallbackMode ¶
type FallbackMode string
FallbackMode controls whether Whodis tries the other protocol after its knowledge-based primary route fails.
const ( FallbackNone FallbackMode = "none" FallbackAnyError FallbackMode = "any-error" )
type Format ¶
type Format string
Format is an output representation for a LookupResult.
func ParseFormat ¶
ParseFormat validates a CLI-facing output format. Common descriptions of the human-facing renderers are accepted as friendly aliases.
type LookupError ¶
LookupError wraps a failure with an actionable classification.
func (*LookupError) Error ¶
func (e *LookupError) Error() string
func (*LookupError) Unwrap ¶
func (e *LookupError) Unwrap() error
type LookupOptions ¶
type LookupOptions struct {
Protocol Protocol
Fallback FallbackMode
Server string
Timeout time.Duration
RefreshBootstrap bool
DNSMode DNSMode
DNSResolver string
}
LookupOptions controls one lookup. A zero-value options struct uses the knowledge-based automatic protocol router, unavailable-only fallback, and no live DNS enrichment.
type LookupResult ¶
type LookupResult struct {
SchemaVersion int `json:"schema_version" yaml:"schema_version"`
Query Target `json:"query" yaml:"query"`
Route RouteDecision `json:"route" yaml:"route"`
FallbackFrom *RouteDecision `json:"fallback_from,omitempty" yaml:"fallback_from,omitempty"`
RetrievedAt time.Time `json:"retrieved_at" yaml:"retrieved_at"`
Object Object `json:"object" yaml:"object"`
Sources []Source `json:"sources" yaml:"sources"`
DNS *DNSResult `json:"dns,omitempty" yaml:"dns,omitempty"`
}
LookupResult is the serializable response returned by Client.Lookup.
type Notice ¶
type Notice struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Description []string `json:"description,omitempty" yaml:"description,omitempty"`
Links []string `json:"links,omitempty" yaml:"links,omitempty"`
}
Notice is a registry-supplied legal or service notice.
type Object ¶
type Object struct {
Kind Kind `json:"kind" yaml:"kind"`
Handle string `json:"handle,omitempty" yaml:"handle,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
UnicodeName string `json:"unicode_name,omitempty" yaml:"unicode_name,omitempty"`
Status []string `json:"status,omitempty" yaml:"status,omitempty"`
Events []Event `json:"events,omitempty" yaml:"events,omitempty"`
Nameservers []string `json:"nameservers,omitempty" yaml:"nameservers,omitempty"`
Entities []Entity `json:"entities,omitempty" yaml:"entities,omitempty"`
Registrar string `json:"registrar,omitempty" yaml:"registrar,omitempty"`
Registry string `json:"registry,omitempty" yaml:"registry,omitempty"`
DNSSEC string `json:"dnssec,omitempty" yaml:"dnssec,omitempty"`
StartAddress string `json:"start_address,omitempty" yaml:"start_address,omitempty"`
EndAddress string `json:"end_address,omitempty" yaml:"end_address,omitempty"`
CIDR []string `json:"cidr,omitempty" yaml:"cidr,omitempty"`
Country string `json:"country,omitempty" yaml:"country,omitempty"`
NetworkType string `json:"network_type,omitempty" yaml:"network_type,omitempty"`
ASN string `json:"asn,omitempty" yaml:"asn,omitempty"`
ASNName string `json:"asn_name,omitempty" yaml:"asn_name,omitempty"`
ASNType string `json:"asn_type,omitempty" yaml:"asn_type,omitempty"`
Notices []Notice `json:"notices,omitempty" yaml:"notices,omitempty"`
Extras map[string][]string `json:"extras,omitempty" yaml:"extras,omitempty"`
}
Object is Whodis's stable normalized registration-data model. Extras keeps protocol or registry-specific values that do not fit the common fields.
type ProjectionField ¶ added in v0.6.0
type ProjectionField string
ProjectionField is a stable, script-friendly view of a normalized result.
const ( FieldExpiration ProjectionField = "expiration" FieldRegistration ProjectionField = "registration" FieldUpdated ProjectionField = "updated" FieldRegistrar ProjectionField = "registrar" FieldRegistry ProjectionField = "registry" FieldStatus ProjectionField = "status" FieldNameservers ProjectionField = "nameservers" FieldDNSSEC ProjectionField = "dnssec" FieldProtocol ProjectionField = "protocol" )
func ParseProjectionField ¶ added in v0.6.0
func ParseProjectionField(value string) (ProjectionField, error)
ParseProjectionField validates a CLI- or UI-facing field name.
type ProtocolAdapter ¶
type ProtocolAdapter interface {
Protocol() Protocol
Lookup(ctx context.Context, target Target, route RouteDecision) (Object, []Source, error)
}
ProtocolAdapter is the extension point for registration-data protocols. Implementations are supplied to NewClient rather than loaded through Go's platform-limited plugin mechanism.
type RenderOptions ¶
RenderOptions changes presentation only; it never changes lookup behavior.
type RouteDecision ¶
type RouteDecision struct {
Protocol Protocol `json:"protocol" yaml:"protocol"`
Endpoint string `json:"endpoint" yaml:"endpoint"`
Alternates []string `json:"alternates,omitempty" yaml:"alternates,omitempty"`
DiscoverySource string `json:"discovery_source" yaml:"discovery_source"`
Reason string `json:"reason" yaml:"reason"`
}
RouteDecision records why an authority and protocol were selected.
type Source ¶
type Source struct {
Protocol Protocol `json:"protocol" yaml:"protocol"`
Endpoint string `json:"endpoint" yaml:"endpoint"`
Authority string `json:"authority,omitempty" yaml:"authority,omitempty"`
Raw string `json:"-" yaml:"-"`
}
Source is one registry response used to construct a result.
type Target ¶
type Target struct {
Original string `json:"original" yaml:"original"`
Canonical string `json:"canonical" yaml:"canonical"`
Kind Kind `json:"kind" yaml:"kind"`
}
Target is a validated, canonical lookup input.
func ParseTarget ¶
ParseTarget classifies and canonicalizes one user supplied lookup target.