client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIError

func APIError(err error) error

APIError turns an SDK error into a short "HTTP 403: message" error. Request headers (and so the token) are never included.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is an API 404.

func ListAccounts

func ListAccounts(ctx context.Context, c *cloudflare.Client) ([]accounts.Account, error)

ListAccounts returns every account the token can see (GET /accounts).

func Messages

func Messages(err error) string

Messages returns the API error messages from a Cloudflare error, joined.

func NewClient

func NewClient(token string) *cloudflare.Client

NewClient builds a Cloudflare SDK client that authenticates with token.

The SDK also reads CLOUDFLARE_API_KEY / CLOUDFLARE_EMAIL from the environment; those headers are stripped so only the bearer token is used.

func ResolveZone

func ResolveZone(ctx context.Context, app *App, nameOrID string) (*zones.Zone, error)

ResolveZone accepts a zone name (example.com) or a 32-char zone ID and returns the zone.

func StatusCode

func StatusCode(err error) int

StatusCode returns the HTTP status of a Cloudflare API error, or 0.

func ValidateToken

func ValidateToken(ctx context.Context, token string) (*user.TokenVerifyResponse, error)

ValidateToken checks a token via GET /user/tokens/verify.

Types

type App

type App struct {
	Client    *cloudflare.Client
	AccountID string
}

App holds the authenticated Cloudflare client and resolved account ID.

func New

func New(ctx context.Context) (*App, error)

New creates an App from the stored (or env) token and the effective account ID. If no account ID is known and the token sees exactly one account, that account is used and cached.

Jump to

Keyboard shortcuts

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