cloudflare

package
v1.37.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cloudflare provides a Cloudflare API v4 client for Commerce.

Used for:

  • Purging cached URLs or Cache-Tag groups after writes
  • Wiring CF cache invalidation into model AfterSave/AfterDelete hooks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConfigured added in v1.36.4

func IsConfigured() bool

IsConfigured returns true when CF credentials and zone are set.

func PurgeAfterWrite added in v1.36.4

func PurgeAfterWrite(tags ...string)

PurgeAfterWrite is a helper that fires a background CF cache-tag purge after a model write. Call from AfterSave/AfterDelete model hooks.

cf := cloudflare.NewBackground()
cf.PurgeAfterWrite("plans", "org:hanzo")

Types

type Client

type Client struct {
	Email    string
	Key      string
	Zone     string
	Endpoint string
	// contains filtered or unexported fields
}

Client is a Cloudflare API v4 client.

func New

func New(c *gin.Context) *Client

New creates a Client from the gin request context using global config.

func NewBackground added in v1.36.4

func NewBackground() *Client

NewBackground creates a Client suitable for background goroutines (no gin context).

func (*Client) Purge

func (c *Client) Purge(zone string, files []string)

Purge removes specific URLs from CF cache. zone defaults to the configured zone if empty.

func (*Client) PurgeEverything added in v1.36.4

func (c *Client) PurgeEverything()

PurgeEverything purges the entire CF cache for the zone. Use sparingly — only for full deploys or catastrophic staleness.

func (*Client) PurgeTags added in v1.36.4

func (c *Client) PurgeTags(tags ...string)

PurgeTags removes all CF cache entries that match the given Cache-Tag values. This is the most targeted invalidation strategy — tag writes at insertion time with SetCFCacheTags() and purge by tag on mutations.

Tags are auto-split on commas so a single comma-joined string is also accepted.

func (*Client) Request

func (c *Client) Request(method, url string, data interface{}) (*http.Response, error)

Request sends an authenticated request to the CF API.

Jump to

Keyboard shortcuts

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