cfapi

package
v5.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 9 Imported by: 1 module, 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

Overview

Package cfapi contains the small set of Cloudflare wire formats used by the DNSControl provider. Requests are executed by cloudflare-go/v7.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountIdentifier

func AccountIdentifier(id string) string

AccountIdentifier returns the account ID unchanged.

func ZoneIdentifier

func ZoneIdentifier(id string) string

ZoneIdentifier returns the zone ID unchanged.

Types

type API

type API struct {
	APIEmail string
	// contains filtered or unexported fields
}

API is a Cloudflare API client.

func New

func New(key, email string, opts ...Option) (*API, error)

New creates an API that authenticates with a key and email.

func NewWithAPIToken

func NewWithAPIToken(token string, opts ...Option) (*API, error)

NewWithAPIToken creates an API that authenticates with a token.

func (*API) CreateDNSRecord

func (a *API) CreateDNSRecord(ctx context.Context, zone string, params CreateDNSRecordParams) (DNSRecord, error)

CreateDNSRecord creates a DNS record.

func (*API) CreateWorkerRoute

func (a *API) CreateWorkerRoute(ctx context.Context, zone string, params CreateWorkerRouteParams) (WorkerRoute, error)

CreateWorkerRoute creates a Worker route.

func (*API) CreateZone

func (a *API) CreateZone(ctx context.Context, name string, jumpStart bool, account Account, zoneType string) (Zone, error)

CreateZone creates a zone.

func (*API) DeleteDNSRecord

func (a *API) DeleteDNSRecord(ctx context.Context, zone, id string) error

DeleteDNSRecord deletes a DNS record.

func (*API) DeleteRulesetRule

func (a *API) DeleteRulesetRule(ctx context.Context, zone string, params DeleteRulesetRuleParams) error

DeleteRulesetRule deletes a rule from a ruleset.

func (*API) DeleteWorkerRoute

func (a *API) DeleteWorkerRoute(ctx context.Context, zone, id string) (WorkerRoute, error)

DeleteWorkerRoute deletes a Worker route.

func (*API) EditUniversalSSLSetting

func (a *API) EditUniversalSSLSetting(ctx context.Context, zone string, setting UniversalSSLSetting) (UniversalSSLSetting, error)

EditUniversalSSLSetting updates a zone's Universal SSL setting.

func (*API) GetEntrypointRuleset

func (a *API) GetEntrypointRuleset(ctx context.Context, zone, phase string) (Ruleset, error)

GetEntrypointRuleset returns a zone's entrypoint ruleset for a phase.

func (*API) ListDNSRecords

func (a *API) ListDNSRecords(ctx context.Context, zone string, _ ListDNSRecordsParams) ([]DNSRecord, any, error)

ListDNSRecords returns all DNS records in a zone.

func (*API) ListWorkerRoutes

func (a *API) ListWorkerRoutes(ctx context.Context, zone string, _ ListWorkerRoutesParams) (WorkerRoutesResponse, error)

ListWorkerRoutes returns a zone's Worker routes.

func (*API) ListZones

func (a *API) ListZones(ctx context.Context) ([]Zone, error)

ListZones returns all zones.

func (*API) Raw

func (a *API) Raw(ctx context.Context, method, path string, body any, _ any) (RawResult, error)

Raw performs an arbitrary API request.

func (*API) SetDebug

func (a *API) SetDebug(enabled bool)

SetDebug enables debug logging.

func (*API) UniversalSSLSettingDetails

func (a *API) UniversalSSLSettingDetails(ctx context.Context, zone string) (UniversalSSLSetting, error)

UniversalSSLSettingDetails returns a zone's Universal SSL setting.

func (*API) UpdateDNSRecord

func (a *API) UpdateDNSRecord(ctx context.Context, zone string, params UpdateDNSRecordParams) (DNSRecord, error)

UpdateDNSRecord updates a DNS record.

func (*API) UpdateEntrypointRuleset

func (a *API) UpdateEntrypointRuleset(ctx context.Context, zone string, params UpdateEntrypointRulesetParams) (Ruleset, error)

UpdateEntrypointRuleset replaces a zone's entrypoint ruleset for a phase.

func (*API) UploadWorker

func (a *API) UploadWorker(ctx context.Context, account string, params CreateWorkerParams) (any, error)

UploadWorker uploads a Worker script.

type Account

type Account struct {
	ID string `json:"id"`
}

Account is a Cloudflare account.

type CreateDNSRecordParams

type CreateDNSRecordParams DNSRecord

CreateDNSRecordParams is the request body for creating a DNS record.

type CreateWorkerParams

type CreateWorkerParams struct {
	ScriptName string
	Script     string
}

CreateWorkerParams is the parameters for uploading a Worker script.

type CreateWorkerRouteParams

type CreateWorkerRouteParams struct {
	Pattern string `json:"pattern"`
	Script  string `json:"script,omitempty"`
}

CreateWorkerRouteParams is the request body for creating a Worker route.

type DNSRecord

type DNSRecord struct {
	ID        string            `json:"id,omitempty"`
	Type      string            `json:"type,omitempty"`
	Name      string            `json:"name,omitempty"`
	Content   string            `json:"content,omitempty"`
	Meta      any               `json:"meta,omitempty"`
	Data      any               `json:"data,omitempty"`
	Priority  *uint16           `json:"priority,omitempty"`
	TTL       int               `json:"ttl,omitempty"`
	Proxied   *bool             `json:"proxied,omitempty"`
	Proxiable bool              `json:"proxiable,omitempty"`
	Comment   string            `json:"comment,omitempty"`
	Tags      []string          `json:"tags,omitempty"`
	Settings  DNSRecordSettings `json:"settings"`
}

DNSRecord is a Cloudflare DNS record.

type DNSRecordSettings

type DNSRecordSettings struct {
	FlattenCNAME *bool `json:"flatten_cname,omitempty"`
}

DNSRecordSettings holds per-record settings.

type DeleteRulesetRuleParams

type DeleteRulesetRuleParams struct {
	RulesetID     string
	RulesetRuleID string
}

DeleteRulesetRuleParams identifies a ruleset rule to delete.

type ListDNSRecordsParams

type ListDNSRecordsParams struct{}

ListDNSRecordsParams is the parameters for listing DNS records.

type ListWorkerRoutesParams

type ListWorkerRoutesParams struct{}

ListWorkerRoutesParams is the parameters for listing Worker routes.

type NotFoundError

type NotFoundError struct{ Err error }

NotFoundError indicates the requested resource does not exist.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) Unwrap

func (e *NotFoundError) Unwrap() error

type Option

type Option func(*API) error

Option configures an API.

func BaseURL

func BaseURL(s string) Option

BaseURL sets the API base URL.

func HTTPClient

func HTTPClient(c *http.Client) Option

HTTPClient sets the HTTP client.

func UsingRetryPolicy

func UsingRetryPolicy(m int, _, _ int) Option

UsingRetryPolicy sets the maximum number of retries.

type PageRule

type PageRule struct {
	ID string `json:"id"`
}

PageRule is a Cloudflare page rule.

type RawResult

type RawResult struct {
	Success bool            `json:"success"`
	Errors  json.RawMessage `json:"errors"`
}

RawResult is the status portion of an API response.

type Ruleset

type Ruleset struct {
	ID    string        `json:"id,omitempty"`
	Rules []RulesetRule `json:"rules"`
}

Ruleset is a Cloudflare ruleset.

type RulesetRule

type RulesetRule struct {
	ID               string                       `json:"id,omitempty"`
	Action           string                       `json:"action"`
	Description      string                       `json:"description,omitempty"`
	Expression       string                       `json:"expression"`
	ActionParameters *RulesetRuleActionParameters `json:"action_parameters,omitempty"`
	Enabled          *bool                        `json:"enabled,omitempty"`
	Ref              string                       `json:"ref,omitempty"`
}

RulesetRule is a rule within a Ruleset.

type RulesetRuleActionParameters

type RulesetRuleActionParameters struct {
	FromValue *RulesetRuleActionParametersFromValue `json:"from_value,omitempty"`
}

RulesetRuleActionParameters holds a rule's action parameters.

type RulesetRuleActionParametersFromValue

type RulesetRuleActionParametersFromValue struct {
	StatusCode          uint16                               `json:"status_code,omitempty"`
	TargetURL           RulesetRuleActionParametersTargetURL `json:"target_url"`
	PreserveQueryString *bool                                `json:"preserve_query_string,omitempty"`
}

RulesetRuleActionParametersFromValue holds redirect action parameters.

type RulesetRuleActionParametersTargetURL

type RulesetRuleActionParametersTargetURL struct {
	Expression string `json:"expression,omitempty"`
}

RulesetRuleActionParametersTargetURL is a redirect's target URL.

type UniversalSSLSetting

type UniversalSSLSetting struct {
	Enabled bool `json:"enabled"`
}

UniversalSSLSetting is a zone's Universal SSL setting.

type UpdateDNSRecordParams

type UpdateDNSRecordParams struct {
	ID       string            `json:"-"`
	Type     string            `json:"type,omitempty"`
	Name     string            `json:"name,omitempty"`
	Content  string            `json:"content,omitempty"`
	Data     any               `json:"data,omitempty"`
	Priority *uint16           `json:"priority,omitempty"`
	TTL      int               `json:"ttl,omitempty"`
	Proxied  *bool             `json:"proxied,omitempty"`
	Comment  *string           `json:"comment,omitempty"`
	Tags     []string          `json:"tags"`
	Settings DNSRecordSettings `json:"settings"`
}

UpdateDNSRecordParams is the request body for updating a DNS record.

type UpdateEntrypointRulesetParams

type UpdateEntrypointRulesetParams struct {
	Phase string        `json:"-"`
	Rules []RulesetRule `json:"rules"`
}

UpdateEntrypointRulesetParams is the request body for updating an entrypoint ruleset.

type WorkerRoute

type WorkerRoute struct {
	ID         string `json:"id,omitempty"`
	Pattern    string `json:"pattern"`
	ScriptName string `json:"script,omitempty"`
}

WorkerRoute is a Cloudflare Worker route.

type WorkerRoutesResponse

type WorkerRoutesResponse struct{ Routes []WorkerRoute }

WorkerRoutesResponse is a list of Worker routes.

type Zone

type Zone struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	NameServers []string `json:"name_servers"`
}

Zone is a Cloudflare zone.

Jump to

Keyboard shortcuts

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