cloudflare

package
v0.0.162 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultReadyTimeout is the max block wait for public readiness.
	DefaultReadyTimeout = 90 * time.Second
	// DefaultReadyPollInterval is the wait-ready poll interval.
	DefaultReadyPollInterval = 2 * time.Second
	// DefaultHeartbeatInterval is how often non-interactive wait logs re-emit
	// the same status signature.
	DefaultHeartbeatInterval = 10 * time.Second
	// DefaultReadyPath is the public path probed for tunnel readiness.
	DefaultReadyPath = "/"
)

Variables

View Source
var ErrReadyTimeout = errors.New("public ready timeout")

ErrReadyTimeout is returned by WaitPublicReady when the public probe never becomes ready.

Functions

func FormatPublicReadyLine added in v0.0.162

func FormatPublicReadyLine(style color.Style, url string, code int, elapsed time.Duration) string

FormatPublicReadyLine formats a successful public readiness line (green when color on).

func FormatReadyTimeoutWarning added in v0.0.162

func FormatReadyTimeoutWarning(style color.Style, url string, timeout time.Duration) string

FormatReadyTimeoutWarning formats a yellow warning when wait-ready times out. Written by callers to stderr typically; returns a full line including trailing \n.

func FormatWaitingProgress added in v0.0.162

func FormatWaitingProgress(code int, elapsed time.Duration, snippet string) string

FormatWaitingProgress builds a single-line wait progress string without trailing \n.

func Handle

func Handle(args []string) error

Handle is production entry: HandleWith(args, HandleOpts{}).

func HandleWith

func HandleWith(args []string, opts HandleOpts) error

HandleWith is the injectable entry used by doctests.

func IsTunnelReady added in v0.0.162

func IsTunnelReady(code int, body string) bool

IsTunnelReady reports whether an HTTP probe result means the tunnel connector is up. Transport failures are not ready (caller passes err separately). Cloudflare connector-down is HTTP 530 with body containing "1033". Any other HTTP status (including origin 404/502) counts as tunnel-up.

func ProbePublic added in v0.0.162

func ProbePublic(ctx context.Context, client HTTPDoer, url string) (code int, body string, ready bool, err error)

ProbePublic GET-probes url once. ready is true when the response indicates the Cloudflare tunnel connector is up (any HTTP response other than CF 530 with body containing "1033").

func PublicProbeURL added in v0.0.162

func PublicProbeURL(domain, readyPath string) string

PublicProbeURL builds https://<domain><path> for readiness probes.

func WaitPublicReady added in v0.0.162

func WaitPublicReady(ctx context.Context, opts WaitReadyOptions) (elapsed time.Duration, err error)

WaitPublicReady polls ProbePublic until the tunnel looks ready or timeout. Progress is collapsed: Interactive uses in-place \r; non-Interactive emits wait lines only on signature change or heartbeat (~10s). On ready / timeout: final line ends with \n. err is nil when ready; err is ErrReadyTimeout (errors.Is) on timeout.

Types

type HTTPDoer added in v0.0.162

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is the injectable HTTP client surface used by readiness probes.

type HandleOpts

type HandleOpts struct {
	// StartSession nil → real cloudflare.StartSession adapter.
	StartSession func(SessionStartOptions) (Session, error)
	// WaitSignal nil → block until SIGINT/SIGTERM.
	WaitSignal func() error
	// WaitReady nil → WaitPublicReady against the public probe URL.
	WaitReady func(WaitReadyOptions) (time.Duration, error)
	// HTTPClient nil → &http.Client{Timeout: 10s} for readiness probes.
	HTTPClient HTTPDoer
	// Stdout/Stderr nil → os.Stdout / os.Stderr (help + user messages).
	Stdout io.Writer
	Stderr io.Writer
	// NoColorEnv nil → os.Getenv("NO_COLOR"); set in tests to control auto mode.
	NoColorEnv *string
}

HandleOpts injects dependencies for tests and production defaults.

type Session

type Session interface {
	Stop() error
	PublicBaseURL() string
}

Session is the stoppable surface returned by StartSession.

type SessionStartOptions

type SessionStartOptions struct {
	Domain     string
	LocalURL   string
	TunnelName string
}

SessionStartOptions is the subset of session config used by the CLI.

type WaitReadyOptions added in v0.0.162

type WaitReadyOptions struct {
	Client       HTTPDoer
	URL          string
	Timeout      time.Duration // 0 → DefaultReadyTimeout
	PollInterval time.Duration // 0 → DefaultReadyPollInterval
	Log          io.Writer     // progress; may be nil
	// Interactive: TTY in-place progress (\r + clear). false = newline + heartbeat.
	Interactive bool
	// HeartbeatInterval: non-interactive re-emit interval for same signature (0 → 10s).
	HeartbeatInterval time.Duration
	Style             color.Style
	// Optional injectables for tests (nil → real time):
	Sleep func(d time.Duration)
	Now   func() time.Time
}

WaitReadyOptions configures WaitPublicReady.

Jump to

Keyboard shortcuts

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