Documentation
¶
Index ¶
- Constants
- Variables
- func FormatPublicReadyLine(style color.Style, url string, code int, elapsed time.Duration) string
- func FormatReadyTimeoutWarning(style color.Style, url string, timeout time.Duration) string
- func FormatWaitingProgress(code int, elapsed time.Duration, snippet string) string
- func Handle(args []string) error
- func HandleWith(args []string, opts HandleOpts) error
- func IsTunnelReady(code int, body string) bool
- func ProbePublic(ctx context.Context, client HTTPDoer, url string) (code int, body string, ready bool, err error)
- func PublicProbeURL(domain, readyPath string) string
- func WaitPublicReady(ctx context.Context, opts WaitReadyOptions) (elapsed time.Duration, err error)
- type HTTPDoer
- type HandleOpts
- type Session
- type SessionStartOptions
- type WaitReadyOptions
Constants ¶
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 ¶
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
FormatPublicReadyLine formats a successful public readiness line (green when color on).
func FormatReadyTimeoutWarning ¶ added in v0.0.162
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
FormatWaitingProgress builds a single-line wait progress string without trailing \n.
func HandleWith ¶
func HandleWith(args []string, opts HandleOpts) error
HandleWith is the injectable entry used by doctests.
func IsTunnelReady ¶ added in v0.0.162
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
PublicProbeURL builds https://<domain><path> for readiness probes.
func WaitPublicReady ¶ added in v0.0.162
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
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 SessionStartOptions ¶
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.