uploadrevision

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentType is the HTTP header name for content type.
	ContentType = "Content-Type"
	// ContentEncoding is the HTTP header name for content encoding.
	ContentEncoding = "Content-Encoding"
	// ContentLength is the HTTP header name for content length.
	ContentLength = "Content-Length"
)

Variables

View Source
var (
	ErrNoFilesUploaded = errors.New("no files uploaded")
	ErrEmptyOrgID      = errors.New("organization ID cannot be empty")
	ErrEmptyRevisionID = errors.New("revision ID cannot be empty")
)

Sentinel errors for common conditions.

Functions

This section is empty.

Types

type CompressionRoundTripper

type CompressionRoundTripper struct {
	// contains filtered or unexported fields
}

CompressionRoundTripper is an http.RoundTripper that automatically compresses request bodies using gzip compression. It wraps another RoundTripper and adds Content-Encoding: gzip header while removing Content-Length to allow proper compression handling.

func NewCompressionRoundTripper

func NewCompressionRoundTripper(drt http.RoundTripper) *CompressionRoundTripper

NewCompressionRoundTripper creates a new CompressionRoundTripper that wraps the provided RoundTripper. If drt is nil, http.DefaultTransport is used. All HTTP requests with a body will be automatically compressed using gzip.

func (*CompressionRoundTripper) RoundTrip

func (crt *CompressionRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface. It compresses the request body using gzip if a body is present, sets the Content-Encoding header to "gzip", and removes the Content-Length header to allow Go's HTTP client to calculate the correct length after compression. Requests without a body are passed through unchanged to the wrapped RoundTripper.

type Config

type Config struct {
	BaseURL string
}

Config contains the configuration for the file upload client.

type ErrorResponseBody

type ErrorResponseBody struct {
	Errors []ResponseError `json:"errors"`
}

ErrorResponseBody contains the complete error response body.

type FakeClientConfig

type FakeClientConfig struct {
	Limits
}

type FakeSealableClient

type FakeSealableClient struct {
	// contains filtered or unexported fields
}

FakeSealableClient is a mock implementation of the SealableClient for testing. It tracks revisions in memory and enforces the revision lifecycle (create -> upload -> seal).

func NewFakeSealableClient

func NewFakeSealableClient(cfg FakeClientConfig) *FakeSealableClient

NewFakeSealableClient creates a new instance of the fake client.

func (*FakeSealableClient) CreateRevision

func (f *FakeSealableClient) CreateRevision(_ context.Context, orgID OrgID) (*ResponseBody, error)

func (*FakeSealableClient) GetLimits

func (f *FakeSealableClient) GetLimits() Limits

func (*FakeSealableClient) GetSealedRevisionFiles

func (f *FakeSealableClient) GetSealedRevisionFiles(revisionID RevisionID) ([]LoadedFile, error)

GetSealedRevisionFiles is a test helper to retrieve files for a sealed revision. It is not part of the SealableClient interface.

func (*FakeSealableClient) SealRevision

func (f *FakeSealableClient) SealRevision(_ context.Context, orgID OrgID, revisionID RevisionID) (*SealResponseBody, error)

func (*FakeSealableClient) UploadFiles

func (f *FakeSealableClient) UploadFiles(_ context.Context, orgID OrgID, revisionID RevisionID, files []UploadFile) error

type FileAccessError

type FileAccessError struct {
	FilePath string
	Err      error
}

FileAccessError indicates a file cannot be accessed or read.

func NewFileAccessError

func NewFileAccessError(filePath string, err error) *FileAccessError

NewFileAccessError creates a new FileAccessError with the given parameters.

func (*FileAccessError) Error

func (e *FileAccessError) Error() string

func (*FileAccessError) Unwrap

func (e *FileAccessError) Unwrap() error

type FileCountLimitError

type FileCountLimitError struct {
	Count int
	Limit int
}

FileCountLimitError indicates too many files were provided.

func NewFileCountLimitError

func NewFileCountLimitError(count, limit int) *FileCountLimitError

NewFileCountLimitError creates a new FileCountLimitError with the given parameters.

func (*FileCountLimitError) Error

func (e *FileCountLimitError) Error() string

type FilePathLengthLimitError

type FilePathLengthLimitError struct {
	FilePath string
	Length   int
	Limit    int
}

FilePathLengthLimitError indicates a file path exceeds the maximum allowed length.

func NewFilePathLengthLimitError

func NewFilePathLengthLimitError(filePath string, length, limit int) *FilePathLengthLimitError

NewFilePathLengthLimitError creates a new FilePathLengthLimitError with the given parameters.

func (*FilePathLengthLimitError) Error

func (e *FilePathLengthLimitError) Error() string

type FileSizeLimitError

type FileSizeLimitError struct {
	FilePath string
	FileSize int64
	Limit    int64
}

FileSizeLimitError indicates a file exceeds the maximum allowed size.

func NewFileSizeLimitError

func NewFileSizeLimitError(filePath string, fileSize, limit int64) *FileSizeLimitError

NewFileSizeLimitError creates a new FileSizeLimitError with the given parameters.

func (*FileSizeLimitError) Error

func (e *FileSizeLimitError) Error() string

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Operation  string
	Body       []byte
}

HTTPError represents an HTTP error response.

func NewHTTPError

func NewHTTPError(statusCode int, status, operation string, body []byte) *HTTPError

NewHTTPError creates a new HTTPError with the given parameters.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HTTPSealableClient

type HTTPSealableClient struct {
	// contains filtered or unexported fields
}

HTTPSealableClient implements the SealableClient interface for file upload operations via HTTP API.

func NewClient

func NewClient(cfg Config, opts ...Opt) *HTTPSealableClient

NewClient creates a new file upload client with the given configuration and options.

func (*HTTPSealableClient) CreateRevision

func (c *HTTPSealableClient) CreateRevision(ctx context.Context, orgID OrgID) (*ResponseBody, error)

CreateRevision creates a new upload revision for the specified organization.

func (*HTTPSealableClient) GetLimits

func (c *HTTPSealableClient) GetLimits() Limits

GetLimits returns the upload Limits defined in the low level client.

func (*HTTPSealableClient) SealRevision

func (c *HTTPSealableClient) SealRevision(ctx context.Context, orgID OrgID, revisionID RevisionID) (*SealResponseBody, error)

SealRevision seals the specified upload revision, marking it as complete.

func (*HTTPSealableClient) UploadFiles

func (c *HTTPSealableClient) UploadFiles(ctx context.Context, orgID OrgID, revisionID RevisionID, files []UploadFile) error

UploadFiles uploads the provided files to the specified revision. It will not close the file descriptors.

type Limits

type Limits struct {
	// FileCountLimit specifies the maximum number of files allowed in a single upload.
	FileCountLimit int
	// FileSizeLimit specifies the maximum allowed file size in bytes.
	FileSizeLimit int64
	// TotalPayloadSizeLimit specifies the maximum total uncompressed payload size in bytes.
	TotalPayloadSizeLimit int64
	// FilePathLengthLimit specifies the maximum allowed file name length in characters.
	FilePathLengthLimit int
}

Limits contains the limits enforced by the low level client.

type LoadedFile

type LoadedFile struct {
	Path    string
	Content string
}

type MultipartError

type MultipartError struct {
	FilePath string
	Err      error
}

MultipartError indicates an error creating multipart form data.

func NewMultipartError

func NewMultipartError(filePath string, err error) *MultipartError

NewMultipartError creates a new MultipartError with the given parameters.

func (*MultipartError) Error

func (e *MultipartError) Error() string

func (*MultipartError) Unwrap

func (e *MultipartError) Unwrap() error

type Opt

type Opt func(*HTTPSealableClient)

Opt is a function that configures an HTTPSealableClient instance.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Opt

WithHTTPClient sets a custom HTTP client for the file upload client.

type OrgID

type OrgID = uuid.UUID

OrgID represents an organization identifier.

type RequestAttributes

type RequestAttributes struct {
	RevisionType RevisionType `json:"revision_type"` //nolint:tagliatelle // API expects snake_case
}

RequestAttributes contains the attributes for creating an upload revision.

type RequestBody

type RequestBody struct {
	Data RequestData `json:"data"`
}

RequestBody contains the complete request body for creating an upload revision.

type RequestData

type RequestData struct {
	Attributes RequestAttributes `json:"attributes"`
	Type       ResourceType      `json:"type"`
}

RequestData contains the data payload for creating an upload revision.

type ResourceType

type ResourceType string

ResourceType represents the type of resource in API requests.

const (
	// ResourceTypeUploadRevision represents an upload revision resource type.
	ResourceTypeUploadRevision ResourceType = "upload_revision"
)

type ResponseAttributes

type ResponseAttributes struct {
	RevisionType RevisionType `json:"revision_type"` //nolint:tagliatelle // API expects snake_case
	Sealed       bool         `json:"sealed"`
}

ResponseAttributes contains the attributes returned when creating an upload revision.

type ResponseBody

type ResponseBody struct {
	Data ResponseData `json:"data"`
}

ResponseBody contains the complete response body when creating an upload revision.

type ResponseData

type ResponseData struct {
	ID         RevisionID         `json:"id"`
	Type       ResourceType       `json:"type"`
	Attributes ResponseAttributes `json:"attributes"`
}

ResponseData contains the data returned when creating an upload revision.

type ResponseError

type ResponseError struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Status string `json:"status"`
	Detail string `json:"detail"`
}

ResponseError represents an error in an API response.

type RevisionID

type RevisionID = uuid.UUID

RevisionID represents a revision identifier.

type RevisionType

type RevisionType string

RevisionType represents the type of revision being created.

const (
	// RevisionTypeSnapshot represents a snapshot revision type.
	RevisionTypeSnapshot RevisionType = "snapshot"
)

type SealRequestAttributes

type SealRequestAttributes struct {
	Sealed bool `json:"sealed"`
}

SealRequestAttributes contains the attributes for sealing an upload revision.

type SealRequestBody

type SealRequestBody struct {
	Data SealRequestData `json:"data"`
}

SealRequestBody contains the complete request body for sealing an upload revision.

type SealRequestData

type SealRequestData struct {
	ID         RevisionID            `json:"id"`
	Type       ResourceType          `json:"type"`
	Attributes SealRequestAttributes `json:"attributes"`
}

SealRequestData contains the data payload for sealing an upload revision.

type SealResponseAttributes

type SealResponseAttributes struct {
	RevisionType RevisionType `json:"revision_type"` //nolint:tagliatelle // API expects snake_case
	Sealed       bool         `json:"sealed"`
}

SealResponseAttributes contains the attributes returned when sealing an upload revision.

type SealResponseBody

type SealResponseBody struct {
	Data SealResponseData `json:"data"`
}

SealResponseBody contains the complete response body when sealing an upload revision.

type SealResponseData

type SealResponseData struct {
	ID         RevisionID             `json:"id"`
	Type       ResourceType           `json:"type"`
	Attributes SealResponseAttributes `json:"attributes"`
}

SealResponseData contains the data returned when sealing an upload revision.

type SealableClient

type SealableClient interface {
	CreateRevision(ctx context.Context, orgID OrgID) (*ResponseBody, error)
	UploadFiles(ctx context.Context, orgID OrgID, revisionID RevisionID, files []UploadFile) error
	SealRevision(ctx context.Context, orgID OrgID, revisionID RevisionID) (*SealResponseBody, error)

	GetLimits() Limits
}

SealableClient defines the interface for file upload API operations.

type SpecialFileError

type SpecialFileError struct {
	FilePath string
	Mode     os.FileMode
}

SpecialFileError indicates a path points to a special file (device, pipe, socket, etc.) instead of a regular file.

func NewSpecialFileError

func NewSpecialFileError(path string, mode os.FileMode) *SpecialFileError

NewSpecialFileError creates a new SpecialFileError with the given path and mode.

func (*SpecialFileError) Error

func (e *SpecialFileError) Error() string

type TotalPayloadSizeLimitError

type TotalPayloadSizeLimitError struct {
	TotalSize int64
	Limit     int64
}

TotalPayloadSizeLimitError indicates the total size of all files exceeds the maximum allowed payload size.

func NewTotalPayloadSizeLimitError

func NewTotalPayloadSizeLimitError(totalSize, limit int64) *TotalPayloadSizeLimitError

NewTotalPayloadSizeLimitError creates a new TotalPayloadSizeLimitError with the given parameters.

func (*TotalPayloadSizeLimitError) Error

type UploadFile

type UploadFile struct {
	Path string // The path of the uploaded file, relative to the root directory.
	File fs.File
}

UploadFile represents a file to be uploaded, containing both the path and file handle.

Jump to

Keyboard shortcuts

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