transport

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package transport is the SDK's HTTP engine: request building (with auth and User-Agent), the retry loop, JSON decoding, and the CDN token cache. The feature packages (run, queue, stream, upload, realtime) are built on a *Core, which the top-level fal package constructs and shares among them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrainAndClose

func DrainAndClose(resp *http.Response)

DrainAndClose consumes and closes a response body so the connection can be reused.

func IsCanceled

func IsCanceled(err error) bool

IsCanceled reports whether err is a context cancellation/deadline.

func SleepCtx

func SleepCtx(ctx context.Context, d time.Duration) error

SleepCtx sleeps for d unless the context is cancelled first.

func WithTimeout

WithTimeout derives a context bounded by d; if d <= 0 the parent is returned with a no-op cancel.

Types

type AuthProvider

type AuthProvider interface {
	AuthHeader(ctx context.Context) (string, error)
}

AuthProvider supplies the Authorization header value for a request. It is implemented by *auth.Manager and injected into Core, so transport never imports the auth package.

type Config

type Config struct {
	HTTPClient     *http.Client
	DefaultTimeout time.Duration

	// Base URLs (scheme+host, no trailing slash).
	RunBase   string
	QueueBase string
	RestBase  string
	CDNBase   string

	UserAgent string
	Auth      AuthProvider
}

Config carries the values Core needs at construction.

type Core

type Core struct {
	HTTPClient     *http.Client
	DefaultTimeout time.Duration

	RunBase   string
	QueueBase string
	RestBase  string
	CDNBase   string

	UserAgent string
	Auth      AuthProvider
	// contains filtered or unexported fields
}

Core is the shared HTTP engine. Its fields are exported so the facade can build it and tests can override base URLs; they must be set once before first use and not mutated afterward. With that contract, Core is safe for concurrent use by multiple goroutines (the only post-construction writers are tests, before any request is issued).

func NewCore

func NewCore(cfg Config) *Core

NewCore builds a Core and wires its CDN token manager.

func (*Core) CDNToken

func (c *Core) CDNToken(ctx context.Context) (Token, error)

CDNToken returns a valid CDN token, fetching or refreshing one if needed.

func (*Core) Do

func (c *Core) Do(req *http.Request) (*http.Response, error)

Do executes req with exponential backoff + jitter. On a 2xx it returns the response with the body still open (the caller must close it). On a terminal non-2xx it returns a *errs.HTTPError. The request body, if any, is rewound between attempts via GetBody.

func (*Core) DoJSON

func (c *Core) DoJSON(req *http.Request, out any) error

DoJSON executes req with retries and unmarshals a 2xx JSON body into out (which may be nil to discard the body).

func (*Core) NewRequest

func (c *Core) NewRequest(ctx context.Context, method, url string, body []byte, headers map[string]string) (*http.Request, error)

NewRequest builds a request with the auth and User-Agent headers applied. Bodies passed as []byte are rewindable so the retry loop can resend them.

type Token

type Token struct {
	BaseURL string
	// contains filtered or unexported fields
}

Token is a short-lived credential for the fal CDN. BaseURL is exported because upload targets it; the token material itself stays unexported and is only emitted through AuthHeader.

func (Token) AuthHeader

func (t Token) AuthHeader() string

AuthHeader returns the Authorization header value for a CDN request.

Jump to

Keyboard shortcuts

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