bootstrap

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Refresh forces a fetch attempt even if a fresh cache entry exists.
	// A failed fetch still falls back to a stale cache or the embedded
	// snapshot rather than erroring.
	Refresh bool
	// Timeout bounds the network fetch. Defaults to 5s.
	Timeout time.Duration
	// CacheDir overrides where bootstrap documents are cached. Empty
	// means the OS user cache directory plus a "plat" subdirectory --
	// the location the CLI uses. A caller-supplied directory is used
	// verbatim, without that subdirectory.
	CacheDir string
	// DisableCache stops plat touching the filesystem at all: nothing is
	// read from or written to a cache, and every load falls through to
	// the network and then the embedded snapshot. Intended for library
	// consumers who do not want an embedded dependency writing to their
	// user's home directory.
	DisableCache bool
	// HTTPClient fetches the bootstrap documents. nil means
	// http.DefaultClient. Exposed so an embedding library can route
	// plat's every outbound request -- not just its RDAP queries --
	// through a caller-supplied transport, for a proxy or for
	// instrumentation.
	HTTPClient *http.Client
}

Options controls Load's behavior.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver maps a TLD to its RDAP service base URL, and an IP address to its RIR's RDAP service base URL, as published by IANA's RDAP bootstrap registries (RFC 9224).

func Load

func Load(ctx context.Context, opts Options) (*Resolver, error)

Load resolves a Resolver using, in order of preference: a fresh local cache, a freshly fetched copy of the IANA bootstrap file (which it then caches), a stale local cache, or the embedded fallback snapshot. It only returns an error if the embedded snapshot itself fails to parse, which should not happen in practice — Load never fails startup purely because the network is unavailable.

The TLD registry (dns.json) is required: a failure to parse it, even from the embedded fallback, fails Load. The IP registries (ipv4.json, ipv6.json) and the ASN registry (asn.json) are populated best-effort afterward -- each falls back independently, and a failure to fetch or parse any one of them leaves that lookup kind unavailable without affecting the others.

func NewASNResolver added in v0.3.0

func NewASNResolver(ranges map[[2]uint32]string) *Resolver

NewASNResolver builds a Resolver from an ASN-range -> RDAP base URL map, bypassing Load's fetch/cache/embedded-fallback chain. It lets other packages' tests (this module's cmd/plat included) point a Resolver at a fake RDAP server without touching the network.

The Resolver this returns covers ASN lookups ONLY: byTLD and byPrefix are left nil, so BaseURL and IPBaseURL always report "no coverage" on it. A domain or IP lookup made with it falls back to WHOIS-only, silently.

func NewCombinedResolver added in v0.5.0

func NewCombinedResolver(byTLD map[string]string, prefixes map[netip.Prefix]string, ranges map[[2]uint32]string) *Resolver

NewCombinedResolver builds a Resolver covering any combination of the three object kinds. Any map may be nil, meaning "no RDAP coverage for that kind", which makes lookups of it fall back to WHOIS-only. It backs the public plat.NewResolver, whose single-kind predecessors made partial coverage easy to request by accident.

func NewIPResolver added in v0.2.0

func NewIPResolver(prefixes map[netip.Prefix]string) *Resolver

NewIPResolver builds a Resolver from an IP-prefix -> RDAP base URL map, bypassing Load's fetch/cache/embedded-fallback chain. It lets other packages' tests (this module's cmd/plat included) point a Resolver at a fake RDAP server without touching the network.

The Resolver this returns covers IP lookups ONLY: byTLD and byASNRange are left nil, so BaseURL and ASNBaseURL always report "no coverage" on it. A domain or ASN lookup made with it falls back to WHOIS-only, silently.

func NewResolver added in v0.1.4

func NewResolver(byTLD map[string]string) *Resolver

NewResolver builds a Resolver directly from a TLD -> RDAP base URL map, bypassing Load's fetch/cache/embedded-fallback chain entirely. It lets other packages' tests (this module's cmd/plat included) point a Resolver at a fake RDAP server without hitting the real network or the real IANA bootstrap file.

The Resolver this returns covers domain lookups ONLY: byPrefix and byASNRange are left nil, so IPBaseURL and ASNBaseURL always report "no coverage" on it. A lookup made with it for an IP address or ASN falls back to WHOIS-only, silently. See NewIPResolver and NewASNResolver for the other two single-kind constructors, and NewCombinedResolver for one that covers all three at once -- that last one is what the public plat.NewResolver builds on, precisely to avoid the accidental partial coverage a single-kind constructor invites.

func (*Resolver) ASNBaseURL added in v0.3.0

func (r *Resolver) ASNBaseURL(asn uint32) (string, bool)

ASNBaseURL returns the RDAP base URL for the RIR holding asn, and whether any delegated range contains it. Unlike IP delegations, IANA's ASN ranges do not overlap, so the first containing range wins -- there is no most-specific-match rule to apply.

func (*Resolver) BaseURL

func (r *Resolver) BaseURL(tld string) (string, bool)

BaseURL returns the RDAP base URL for tld and whether the TLD has RDAP coverage at all. tld should not include a leading dot.

func (*Resolver) IPBaseURL added in v0.2.0

func (r *Resolver) IPBaseURL(addr netip.Addr) (string, bool)

IPBaseURL returns the RDAP base URL for the RIR holding addr, and whether any delegated range covers it. When delegations overlap (a /8 held by one RIR with a /24 sub-delegated to another), the most specific prefix wins -- matching how the IANA registry is meant to be read.

Jump to

Keyboard shortcuts

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