Documentation
¶
Overview ¶
Package exportapi provides shared transport-agnostic HTTP workflow for export adapters.
Index ¶
- Constants
- func WriteError(res Response, err error)
- type AsyncRequester
- type AsyncResponse
- type Config
- type Controller
- type DefinitionResolver
- type DefinitionResolverFunc
- type DownloadPayload
- type DownloadResponder
- type ErrorBody
- type ErrorResponse
- type IdempotencyStore
- type JSONRequestDecoder
- type MemoryIdempotencyStore
- type QueryDecoder
- type QueryRequestDecoder
- type Request
- type RequestDecoder
- type Response
- type StreamOption
- type StreamOptions
Constants ¶
const DefaultMaxBufferBytes int64 = 8 * 1024 * 1024
DefaultMaxBufferBytes is the fallback buffer limit when streaming is unavailable.
Variables ¶
This section is empty.
Functions ¶
func WriteError ¶
Types ¶
type AsyncRequester ¶
type AsyncRequester interface {
RequestExport(ctx context.Context, actor export.Actor, req export.ExportRequest) (export.ExportRecord, error)
}
AsyncRequester enqueues async exports (e.g., a job scheduler).
type AsyncResponse ¶
type AsyncResponse struct {
ID string `json:"id"`
StatusURL string `json:"status_url"`
DownloadURL string `json:"download_url"`
}
AsyncResponse describes async export responses.
type Config ¶
type Config struct {
Service export.Service
Runner *export.Runner
Store export.ArtifactStore
Guard export.Guard
ActorProvider export.ActorProvider
DeliveryPolicy export.DeliveryPolicy
AsyncRequester AsyncRequester
BasePath string
HistoryPath string
SignedURLTTL time.Duration
IdempotencyStore IdempotencyStore
IdempotencyTTL time.Duration
Logger export.Logger
IDGenerator func() string
RequestDecoder RequestDecoder
QueryRequestDecoder RequestDecoder
DefinitionResolver DefinitionResolver
MaxBufferBytes int64
}
Config configures the shared export API controller.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller exposes export API handlers for multiple transports.
func NewController ¶
func NewController(cfg Config) *Controller
NewController creates a shared export API controller.
func (*Controller) BasePath ¶
func (c *Controller) BasePath() string
BasePath returns the configured base path.
func (*Controller) HistoryPath ¶
func (c *Controller) HistoryPath() string
HistoryPath returns the configured history path.
func (*Controller) Serve ¶
func (c *Controller) Serve(req Request, res Response)
Serve routes export endpoints using the shared controller.
type DefinitionResolver ¶
type DefinitionResolver interface {
ResolveDefinition(ctx context.Context, req export.ExportRequest) (string, error)
}
DefinitionResolver resolves a definition name for requests that omit it.
func NewDefinitionResolver ¶
func NewDefinitionResolver(registry *export.DefinitionRegistry) DefinitionResolver
NewDefinitionResolver returns a resolver that maps request resources to definitions.
type DefinitionResolverFunc ¶
DefinitionResolverFunc adapts a function to a DefinitionResolver.
func (DefinitionResolverFunc) ResolveDefinition ¶
func (f DefinitionResolverFunc) ResolveDefinition(ctx context.Context, req export.ExportRequest) (string, error)
ResolveDefinition resolves the definition name.
type DownloadPayload ¶ added in v0.2.0
type DownloadPayload struct {
ContentType string
Filename string
ExportID string
Size int64
MaxBufferBytes int64
Reader io.Reader
Bytes []byte
}
DownloadPayload describes a file download response.
type DownloadResponder ¶ added in v0.2.0
type DownloadResponder interface {
WriteDownload(ctx context.Context, payload DownloadPayload) error
WriteStream(ctx context.Context, contentType string, r io.Reader, opts ...StreamOption) error
}
DownloadResponder provides streaming download helpers.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorBody `json:"error"`
}
ErrorResponse describes JSON error responses.
type IdempotencyStore ¶
type IdempotencyStore interface {
Get(ctx context.Context, key string) (string, bool, error)
Set(ctx context.Context, key, exportID string, ttl time.Duration) error
}
IdempotencyStore stores idempotency keys.
type JSONRequestDecoder ¶
type JSONRequestDecoder struct {
QueryDecoder QueryDecoder
}
JSONRequestDecoder decodes JSON into export requests.
func (JSONRequestDecoder) Decode ¶
func (d JSONRequestDecoder) Decode(req Request) (export.ExportRequest, error)
Decode decodes a JSON request body into an export request.
type MemoryIdempotencyStore ¶
type MemoryIdempotencyStore struct {
// contains filtered or unexported fields
}
MemoryIdempotencyStore stores idempotency keys in memory.
func NewMemoryIdempotencyStore ¶
func NewMemoryIdempotencyStore() *MemoryIdempotencyStore
NewMemoryIdempotencyStore creates an in-memory store.
type QueryDecoder ¶
type QueryDecoder func(definition, variant string, raw json.RawMessage) (any, error)
QueryDecoder converts raw JSON query payloads into typed values.
type QueryRequestDecoder ¶
type QueryRequestDecoder struct{}
QueryRequestDecoder decodes querystring payloads into export requests.
func (QueryRequestDecoder) Decode ¶
func (d QueryRequestDecoder) Decode(req Request) (export.ExportRequest, error)
Decode parses query params into an export request.
type Request ¶
type Request interface {
Context() context.Context
Method() string
Path() string
URL() *url.URL
Header(name string) string
Query(name string) string
Body() io.ReadCloser
}
Request provides minimal request access for transport adapters.
type RequestDecoder ¶
type RequestDecoder interface {
Decode(req Request) (export.ExportRequest, error)
}
RequestDecoder parses an HTTP request into an export request.
type Response ¶
type Response interface {
DownloadResponder
SetHeader(name, value string)
DelHeader(name string)
WriteHeader(status int)
Write(data []byte) (int, error)
WriteJSON(status int, payload any) error
Writer() (io.Writer, bool)
Redirect(location string, status int) error
}
Response provides a minimal response interface for transport adapters.
type StreamOption ¶ added in v0.2.0
type StreamOption func(*StreamOptions)
StreamOption applies stream options.
func WithContentLength ¶ added in v0.2.0
func WithContentLength(length int64) StreamOption
WithContentLength sets the content length header.
func WithExportID ¶ added in v0.2.0
func WithExportID(exportID string) StreamOption
WithExportID sets the export id response header.
func WithFilename ¶ added in v0.2.0
func WithFilename(filename string) StreamOption
WithFilename sets the download filename.
func WithMaxBufferBytes ¶ added in v0.2.0
func WithMaxBufferBytes(max int64) StreamOption
WithMaxBufferBytes sets the maximum buffer size when streaming is unavailable.
type StreamOptions ¶ added in v0.2.0
type StreamOptions struct {
Filename string
ExportID string
ContentLength int64
MaxBufferBytes int64
}
StreamOptions configures download stream responses.
func ResolveStreamOptions ¶ added in v0.2.0
func ResolveStreamOptions(opts ...StreamOption) StreamOptions
ResolveStreamOptions applies stream options.