Help us shape the future of Go! Take the 2026 Go Developer Survey

cfapi

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cfapi is the shared transport for every Cloudflare v4 API call mailctl makes: DNS, Email Routing, Email Sending, and Workers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List[T any](ctx context.Context, c *Client, path string) ([]T, error)

List fetches every page of a paginated collection endpoint. path may already carry a query string; page and per_page are appended to it.

If pagination does not terminate within maxListPages, List returns an error. We return an error rather than silently truncating because a partial result would cause the diff engine to think records were deleted when we merely failed to fetch all pages.

Types

type Client

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

func New

func New(baseURL, token string) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body, result any) error

Do performs one request. body is JSON-marshalled when non-nil; result is JSON-unmarshalled from the envelope's result field when non-nil.

func (*Client) Multipart

func (c *Client) Multipart(ctx context.Context, method, path string, parts []Part, result any) error

Multipart performs a multipart/form-data request.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, path string) (body []byte, contentType string, found bool, err error)

Raw performs a GET and returns the response body unparsed, for endpoints that answer with something other than the JSON envelope. found is false when the resource does not exist, which is a normal state rather than an error. contentType is the response's Content-Type header, since some of those endpoints answer with a shape (e.g. multipart/form-data) that callers must detect before they can parse the body.

func (*Client) String

func (c *Client) String() string

String redacts the token so that printing a Client cannot leak it.

type Part

type Part struct {
	Name        string
	Filename    string
	ContentType string
	Data        []byte
}

Part is one section of a multipart upload, used for Worker script uploads.

Jump to

Keyboard shortcuts

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