Documentation
¶
Index ¶
- Variables
- func ConsoleURL(accountID, workerName string) string
- func CreateTail(accountID, token, workerName string) (tailID, wsURL string, err error)
- func DeleteKV(accountID, token, namespaceID string) error
- func DeleteTail(accountID, token, workerName, tailID string) error
- func DeleteWorker(accountID, token, workerName string) error
- func Deploy(params DeployParams) error
- func EnsureAccountAccess(token, accountID string) error
- func FindKV(accountID, token, title string) (namespaceID string, err error)
- func FindOrCreateKV(accountID, token, title string) (namespaceID string, err error)
- func GenerateTestWorkerCode() string
- func GenerateWorkerCode() string
- func GetWranglerToken() (string, error)
- func InstallWrangler() error
- func IsWranglerInstalled() bool
- func RunWranglerLogin() error
- func RunWranglerLogout() error
- func SetSchedule(accountID, token, workerName, cron string) error
- func SetSecret(accountID, token, workerName, name, value string) error
- func UploadWorker(accountID, token, workerName, code, kvNSID string) error
- func WriteKVValue(accountID, token, nsID, key, value string) error
- type AuthResult
- type AuthState
- type DeployParams
- type VerifyResult
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ConsoleURL ¶
func CreateTail ¶
CreateTail starts a tail session for real-time worker logs. POST /accounts/{accountId}/workers/scripts/{workerName}/tails Returns the tail session ID and WebSocket URL.
func DeleteTail ¶
DeleteTail removes a tail session. DELETE /accounts/{accountId}/workers/scripts/{workerName}/tails/{tailId}
func DeleteWorker ¶
DeleteWorker deletes a worker script.
func Deploy ¶
func Deploy(params DeployParams) error
Deploy orchestrates the full worker deployment sequence:
- Find/create KV namespace (per-worker isolation)
- Write refresh token to KV (initial value)
- Upload worker with KV binding
- Set cron schedule
- Store secrets (REFRESH_TOKEN, TIMEZONE, optional NOTIFICATION_CONFIG)
func EnsureAccountAccess ¶
func FindOrCreateKV ¶
FindOrCreateKV finds a KV namespace by title, creating it if not found. Returns the namespace ID.
func GenerateTestWorkerCode ¶
func GenerateTestWorkerCode() string
func GenerateWorkerCode ¶
func GenerateWorkerCode() string
func GetWranglerToken ¶
GetWranglerToken calls `wrangler auth token --json`. Returns a Bearer token for the CF API, or an error. For api_key auth: CF API uses X-Auth-Key + X-Auth-Email headers, but this is legacy — we reject it and suggest switching to API token.
func InstallWrangler ¶
func InstallWrangler() error
InstallWrangler attempts to install wrangler globally. Tries npm first, then brew on macOS.
func IsWranglerInstalled ¶
func IsWranglerInstalled() bool
IsWranglerInstalled checks if wrangler is on PATH.
func RunWranglerLogin ¶
func RunWranglerLogin() error
RunWranglerLogin runs `wrangler login` interactively (needs TTY).
func RunWranglerLogout ¶ added in v0.0.2
func RunWranglerLogout() error
RunWranglerLogout runs `wrangler logout` to clear stored credentials.
func SetSchedule ¶
SetSchedule sets cron triggers for a worker. Body is an ARRAY of cron objects: [{"cron": "..."}]
func SetSecret ¶
SetSecret sets a worker secret. Body uses "text" field (NOT "value") and "type": "secret_text".
func UploadWorker ¶
UploadWorker uploads worker code as a multipart form with metadata. This is the most complex CF API call — uses multipart/form-data with:
- Part 1: "worker.js" with Content-Type: application/javascript+module
- Part 2: "metadata" with Content-Type: application/json (bindings, main_module, etc.)
func WriteKVValue ¶
WriteKVValue writes a plain text value to a KV key. Note: body is raw string (NOT JSON-encoded), per CF API spec.
Types ¶
type AuthResult ¶
type AuthResult struct {
Token string
AccountID string
Source string // "env", "wrangler", "manual"
}
AuthResult holds the resolved authentication credentials.
func ResolveFromEnv ¶
func ResolveFromEnv() *AuthResult
ResolveFromEnv returns token from CLOUDFLARE_API_TOKEN env var if set.
type AuthState ¶
type AuthState int
AuthState represents the current Cloudflare authentication status.
func DetectAuthState ¶
func DetectAuthState() AuthState
DetectAuthState checks available auth methods without prompting.
type DeployParams ¶
type DeployParams struct {
Token string
AccountID string
WorkerName string
WorkerCode string
RefreshToken string
CronExpression string
Timezone string
NotificationConfig string // optional JSON: {"slackWebhook":"...","failureOnly":true}
OnProgress func(step string)
}
DeployParams holds all parameters needed for a full worker deployment.
type VerifyResult ¶
func VerifyToken ¶
func VerifyToken(token string) (*VerifyResult, error)
VerifyToken verifies the CF token and returns account info. Supports both dashboard API tokens (/user/tokens/verify) and wrangler OAuth tokens (/user) — OAuth tokens don't work with /tokens/verify.