cloud

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cloud fetches the IP ranges that cloud providers publish (AWS, Google Cloud, Cloudflare) and answers "which provider/region owns this address?". Standard library only. Nothing is fetched at import time; callers decide when to refresh and should cache the result.

Index

Constants

View Source
const (
	DefaultAWSURL          = "https://ip-ranges.amazonaws.com/ip-ranges.json"
	DefaultGCPURL          = "https://www.gstatic.com/ipranges/cloud.json"
	DefaultCloudflareV4URL = "https://www.cloudflare.com/ips-v4"
	DefaultCloudflareV6URL = "https://www.cloudflare.com/ips-v6"
)

Official feed locations.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Prefix   netip.Prefix
	Provider Provider
	Region   string // empty when the feed has none
	Service  string
}

Entry is one published prefix.

type Fetcher

type Fetcher struct {
	Client                           *http.Client
	AWSURL, GCPURL                   string
	CloudflareV4URL, CloudflareV6URL string
	// MaxBytes caps each response body (default 32 MiB).
	MaxBytes int64
}

Fetcher downloads feeds. The zero value uses http.DefaultClient and the official URLs; override fields for proxies, mirrors or tests.

func (*Fetcher) AWS

func (f *Fetcher) AWS(ctx context.Context) ([]Entry, error)

AWS fetches ip-ranges.json.

func (*Fetcher) All

func (f *Fetcher) All(ctx context.Context) ([]Entry, error)

All fetches every provider; the first error aborts.

func (*Fetcher) Cloudflare

func (f *Fetcher) Cloudflare(ctx context.Context) ([]Entry, error)

Cloudflare fetches the plain-text ips-v4 and ips-v6 lists.

func (*Fetcher) GCP

func (f *Fetcher) GCP(ctx context.Context) ([]Entry, error)

GCP fetches Google Cloud's cloud.json (customer-usable ranges).

type Index

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

Index answers ownership queries. Immutable after NewIndex; safe for concurrent use.

func NewIndex

func NewIndex(entries []Entry) *Index

NewIndex builds an index. When prefixes repeat, the last entry wins.

func (*Index) Lookup

func (idx *Index) Lookup(a netip.Addr) (Entry, bool)

Lookup returns the most specific entry containing a.

func (*Index) Set

func (idx *Index) Set(p Provider) *ipx.IPSet

Set returns every address published by provider p (empty if unknown).

type Provider

type Provider string

Provider names a cloud.

const (
	AWS        Provider = "aws"
	GCP        Provider = "gcp"
	Cloudflare Provider = "cloudflare"
)

Jump to

Keyboard shortcuts

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