Documentation
¶
Index ¶
- Constants
- Variables
- type DownloadError
- type HandlerFuncs
- type Identifier
- type Manager
- func (m *Manager) Download(ctx context.Context, raw string, dstPath string) error
- func (m *Manager) Open(ctx context.Context, raw string) (*Stream, error)
- func (m *Manager) Register(scheme string, handler ResourceHandler) error
- func (m *Manager) Upload(ctx context.Context, scheme string, in UploadInput) (Identifier, error)
- type OpenError
- type Option
- func WithDataMaxBytes(maxBytes int64) Option
- func WithHTTPClient(client *http.Client) Option
- func WithHTTPEnabled(enabled bool) Option
- func WithMaxBytes(maxBytes int64) Option
- func WithRedirectLimit(limit int) Option
- func WithRetry(attempts int, baseDelay time.Duration, maxDelay time.Duration) Option
- func WithTimeoutQuota(timeout time.Duration) Option
- type Options
- type ParseError
- type ResourceHandler
- type Stream
- type UploadError
- type UploadInput
Constants ¶
const ( // ErrCodeResourceUnsupportedScheme means no handler is registered for the resource scheme. ErrCodeResourceUnsupportedScheme = 20200 // ErrCodeResourceOpenUnsupported means a handler does not implement opening. ErrCodeResourceOpenUnsupported = 20201 // ErrCodeResourceUploadUnsupported means a handler does not implement uploading. ErrCodeResourceUploadUnsupported = 20202 // ErrCodeResourceSizeLimitExceeded means a resource body exceeded the configured size limit. ErrCodeResourceSizeLimitExceeded = 20203 // ErrCodeResourceTimeoutBudgetExhausted means the current context deadline has no remaining budget. ErrCodeResourceTimeoutBudgetExhausted = 10120 )
Variables ¶
var ( // ErrUnsupportedScheme means no handler is registered for the resource scheme. ErrUnsupportedScheme = datax.NewError(ErrCodeResourceUnsupportedScheme, "resource: unsupported scheme", nil) // ErrOpenUnsupported means a handler does not implement opening. ErrOpenUnsupported = datax.NewError(ErrCodeResourceOpenUnsupported, "resource: open unsupported", nil) // ErrUploadUnsupported means a handler does not implement uploading. ErrUploadUnsupported = datax.NewError(ErrCodeResourceUploadUnsupported, "resource: upload unsupported", nil) // ErrSizeLimitExceeded means a resource body exceeded the configured size limit. ErrSizeLimitExceeded = datax.NewError(ErrCodeResourceSizeLimitExceeded, "resource: size limit exceeded", nil) // ErrTimeoutBudgetExhausted means the current context deadline has no remaining budget. ErrTimeoutBudgetExhausted = datax.NewError(ErrCodeResourceTimeoutBudgetExhausted, "resource: timeout budget exhausted", nil) )
Functions ¶
This section is empty.
Types ¶
type DownloadError ¶
DownloadError wraps download failures.
func (*DownloadError) Unwrap ¶
func (e *DownloadError) Unwrap() error
Unwrap returns the root cause.
type HandlerFuncs ¶
type HandlerFuncs struct {
OpenFunc func(ctx context.Context, id Identifier) (*Stream, error)
UploadFunc func(ctx context.Context, in UploadInput) (Identifier, error)
}
HandlerFuncs adapts functions into a ResourceHandler.
func (HandlerFuncs) Open ¶
func (h HandlerFuncs) Open(ctx context.Context, id Identifier) (*Stream, error)
Open implements ResourceHandler.
func (HandlerFuncs) Upload ¶
func (h HandlerFuncs) Upload(ctx context.Context, in UploadInput) (Identifier, error)
Upload implements ResourceHandler.
type Identifier ¶
type Identifier struct {
Raw string
Params map[string]string
SourceURI string
Scheme string
AuthID string
MediaType string
}
Identifier is the parsed form of an ofa-res resource identifier.
func Parse ¶
func Parse(raw string) (Identifier, error)
Parse parses an ofa-res resource identifier without doing network or disk IO.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager routes resource operations to handlers by source scheme.
func NewManager ¶
NewManager creates a Manager with built-in handlers for https, data, and optionally http.
func (*Manager) Register ¶
func (m *Manager) Register(scheme string, handler ResourceHandler) error
Register registers or replaces a handler for a scheme.
func (*Manager) Upload ¶
func (m *Manager) Upload(ctx context.Context, scheme string, in UploadInput) (Identifier, error)
Upload routes an upload request to the handler registered for scheme.
type OpenError ¶
type OpenError struct {
Identifier Identifier
Err error
}
OpenError wraps resource open failures.
type Option ¶
type Option func(*Options)
Option configures a Manager.
func WithDataMaxBytes ¶
WithDataMaxBytes sets the default data URL body size limit.
func WithHTTPClient ¶
WithHTTPClient sets the client used by default http/https handlers.
func WithHTTPEnabled ¶
WithHTTPEnabled toggles the built-in http handler. https remains enabled.
func WithMaxBytes ¶
WithMaxBytes sets the default stream and download body size limit.
func WithRedirectLimit ¶
WithRedirectLimit sets the default HTTP redirect limit.
func WithTimeoutQuota ¶
WithTimeoutQuota sets the default timeout when ctx has no deadline.
type Options ¶
type Options struct {
HTTPClient *http.Client
MaxBytes int64
DataMaxBytes int64
TimeoutQuota time.Duration
ConnectTimeout time.Duration
RedirectLimit int
RetryAttempts int
RetryBaseDelay time.Duration
RetryMaxDelay time.Duration
EnableHTTP bool
}
Options controls Manager defaults and built-in handlers.
type ParseError ¶
ParseError wraps resource identifier parse failures.
type ResourceHandler ¶
type ResourceHandler interface {
Open(ctx context.Context, id Identifier) (*Stream, error)
Upload(ctx context.Context, in UploadInput) (Identifier, error)
}
ResourceHandler opens and uploads resources for a specific source scheme.
type Stream ¶
type Stream struct {
Body io.ReadCloser
MediaType string
Filename string
Size int64
SourceURI string
Headers http.Header
}
Stream is an opened resource stream. Callers must close Body.
type UploadError ¶
UploadError wraps upload failures.