Documentation
¶
Overview ¶
Package hosted is the one HTTP client the CLI's hosted-service commands (deploy, functions, static, automation) share: the URL check, the bearer header, the error envelope and retries.
Index ¶
- Constants
- Variables
- func Backoff(attempt int, retryAfter string) time.Duration
- func CheckURL(raw string) error
- func Idempotent(method string) bool
- func IsLoopback(host string) bool
- func NeverSent(err error) bool
- func Retryable(status int, idempotent bool) bool
- func Seg(s string) string
- func Short(s string, n int) string
- type Client
- type Error
Constants ¶
const DefaultURL = "https://api.altengine.net"
DefaultURL is the hosted service's API origin.
Variables ¶
var ( MaxAttempts = 4 BaseBackoff = 500 * time.Millisecond Sleep = time.Sleep )
Retries: attempts in all, the first backoff (doubled each time), and the sleep between them (replaced in tests).
Functions ¶
func Backoff ¶
Backoff is the wait before attempt+1: BaseBackoff doubled per attempt, or the server's Retry-After in seconds, capped at 30s.
func CheckURL ¶
CheckURL refuses a base URL the API key must not be sent to: anything but https, except plain http to this machine (an emulator or a local proxy).
func Idempotent ¶
Idempotent reports whether a request with this method may be repeated after an ambiguous failure. A POST may deploy twice, so it is not.
func IsLoopback ¶
IsLoopback reports whether host names this machine.
func NeverSent ¶
NeverSent reports whether a transport error happened before the request reached the server (no connection, no address), which makes a retry safe whatever the method.
func Retryable ¶
Retryable reports whether an answer is worth another attempt. 429 and 503 turn a request away before it is acted on, so any method retries them; 502 and 504 may come after it was acted on, so only a request that is safe to repeat does.
Types ¶
type Client ¶
type Client struct {
BaseURL string
APIKey string
// Timeout per request. Generous by default: a large bundle on a slow link is a legitimately
// slow request, and a timeout leaves someone unsure whether it landed.
Timeout time.Duration
}
Client calls the hosted API with an org API key.