client

package
v0.0.0-...-1bd3920 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const ClientHostnameHeader = "Client-Hostname"

Variables

View Source
var (
	// ErrDone indicates an iterator is expended.
	ErrDone = errors.New("no more items in iterator")

	// ErrUploaded indicates a file upload is unnecessary as the service already
	// has the required data.
	ErrUploaded = errors.New("file is already uploaded")

	// ErrFileNotFound indicates that a file doesn't exist.
	ErrFileNotFound = errors.New("file not found")
)

Functions

This section is empty.

Types

type BatchDownloader

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

BatchDownloader is an iterator over file batches.

func (*BatchDownloader) Next

func (d *BatchDownloader) Next() (*FileBatch, error)

Next gets the next batch of files. If the iterator is expended it will return the sentinel error Done.

type Client

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

Client provides an API interface to FileHeap.

func New

func New(address string, options ...Option) (*Client, error)

New creates a new client connected the given address.

Address should be in the form [scheme://]host[:port], where scheme defaults to "https" and port defaults to the standard port for the given scheme, i.e. 80 for http and 443 for https.

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL returns the base URL of the client.

func (*Client) Dataset

func (c *Client) Dataset(id string) *DatasetRef

Dataset creates a reference to an existing dataset by ID.

func (*Client) NewDataset

func (c *Client) NewDataset(ctx context.Context) (*DatasetRef, error)

NewDataset creates a new collection of files.

type DatasetOpts

type DatasetOpts struct{}

DatasetOpts allows clients to set options during creation of a new dataset.

type DatasetRef

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

DatasetRef is a reference to a dataset.

Callers should not assume the ref is valid.

func (*DatasetRef) AddFile

func (d *DatasetRef) AddFile(
	ctx context.Context,
	filename string,
	digest []byte,
) error

AddFile to a dataset when the digest is already known.

func (*DatasetRef) Delete

func (d *DatasetRef) Delete(ctx context.Context) error

Delete deletes a dataset and all of its files.

This invalidates the DatasetRef and all associated file references.

func (*DatasetRef) DeleteFile

func (d *DatasetRef) DeleteFile(ctx context.Context, filename string) error

DeleteFile deletes a file in the dataset.

func (*DatasetRef) DownloadBatch

func (d *DatasetRef) DownloadBatch(ctx context.Context, files Iterator) *BatchDownloader

DownloadBatch creates a BatchDownloader.

func (*DatasetRef) FileInfo

func (d *DatasetRef) FileInfo(ctx context.Context, filename string) (*api.FileInfo, error)

FileInfo returns metadata about a file in the dataset. Returns ErrFileNotFound if the file does not exist.

func (*DatasetRef) Files

Files returns an iterator over all files in the dataset.

func (*DatasetRef) Info

func (d *DatasetRef) Info(ctx context.Context) (*api.Dataset, error)

Info returns metadata about the dataset.

func (*DatasetRef) Name

func (d *DatasetRef) Name() string

Name returns the dataset's unique identifier.

func (*DatasetRef) NewDeleteBatch

func (d *DatasetRef) NewDeleteBatch() *DeleteBatch

NewDeleteBatch creates a DeleteBatch.

func (*DatasetRef) NewUploadBatch

func (d *DatasetRef) NewUploadBatch() *UploadBatch

NewUploadBatch creates an UploadBatch.

func (*DatasetRef) ReadFile

func (d *DatasetRef) ReadFile(ctx context.Context, filename string) (io.ReadCloser, error)

ReadFile reads the contents of a stored file.

If the file doesn't exist, this returns ErrFileNotFound.

The caller must call Close on the returned Reader when finished reading.

func (*DatasetRef) ReadFileRange

func (d *DatasetRef) ReadFileRange(
	ctx context.Context,
	filename string,
	offset, length int64,
) (io.ReadCloser, error)

ReadFileRange reads at most length bytes from a file starting at the given offset. If length is negative, the file is read until the end. Length must not be zero.

If the file doesn't exist, this returns ErrFileNotFound.

The caller must call Close on the returned Reader when finished reading.

func (*DatasetRef) Seal

func (d *DatasetRef) Seal(ctx context.Context) error

Seal makes a dataset read-only. This operation is not reversible.

func (*DatasetRef) URL

func (d *DatasetRef) URL() string

URL gets the URL of a dataset.

func (*DatasetRef) WriteFile

func (d *DatasetRef) WriteFile(
	ctx context.Context,
	filename string,
	source io.Reader,
	size int64,
) error

WriteFile writes the source to the filename in this dataset.

The file will be replaced if it exists or created if not. The file becomes available when Close returns successfully. The previous file is readable until the new file replaces it.

It is the caller's responsibility to call Close when writing is complete.

type DeleteBatch

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

DeleteBatch contains a list of files to delete from a dataset.

func (*DeleteBatch) AddFile

func (b *DeleteBatch) AddFile(path string) error

AddFile adds a file to the batch.

func (*DeleteBatch) Delete

func (b *DeleteBatch) Delete(ctx context.Context) error

Delete all paths in the batch.

func (*DeleteBatch) HasCapacity

func (b *DeleteBatch) HasCapacity() bool

HasCapacity checks whether the batch has capacity for another file.

func (*DeleteBatch) Length

func (b *DeleteBatch) Length() int

Length gets the number of files in a batch.

type FileBatch

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

FileBatch is a batch of files with readers.

func (*FileBatch) Length

func (b *FileBatch) Length() int

Length gets the number of files in a batch.

func (*FileBatch) Next

func (b *FileBatch) Next() (*api.FileInfo, io.ReadCloser, error)

Next gets the next file and its reader in the iterator. If the iterator is expended it will return the sentinel error Done. The batch is closed if Next returns an error. Future calls will return the same error.

func (*FileBatch) Size

func (b *FileBatch) Size() int64

Size of the batch in bytes.

type FileIterator

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

FileIterator is an iterator over files within a dataset.

func (*FileIterator) Next

func (i *FileIterator) Next() (*api.FileInfo, error)

Next gets the next file in the iterator. If iterator is expended it will return the sentinel error Done.

type FileIteratorOptions

type FileIteratorOptions struct {
	// Include presigned URLs to download each file. Note that this may result in slower response times.
	IncludeURLs bool

	// Maximum number of files to fetch in a single request.
	PageSize int

	// Prefix within the dataset. Only files that start with the prefix will be included.
	Prefix string
}

FileIteratorOptions provides optional configuration to a file iterator.

type Iterator

type Iterator interface {
	Next() (*api.FileInfo, error)
}

Iterator is an iterator over file information.

type Option

type Option interface {
	Apply(c *Client)
}

Option allows a caller to configure additional options on a client.

func WithToken

func WithToken(token string) Option

WithToken returns an Option which specifies a token to be used for authentication.

type TraceResult

type TraceResult struct {
	Start                time.Time
	DNSStart             time.Time
	DNSDone              time.Time
	ConnectStart         time.Time
	ConnectDone          time.Time
	TLSHandshakeStart    time.Time
	TLSHandshakeDone     time.Time
	GotFirstResponseByte time.Time
}

func NewResult

func NewResult() *TraceResult

func (*TraceResult) Fields

func (r *TraceResult) Fields() logrus.Fields

type UploadBatch

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

UploadBatch contains files and their readers.

func (*UploadBatch) AddFile

func (b *UploadBatch) AddFile(path string, reader io.Reader, size int64) error

AddFile adds a file to the batch.

func (*UploadBatch) HasCapacity

func (b *UploadBatch) HasCapacity(size int64) bool

HasCapacity checks whether the batch has capacity for a file with the given size.

func (*UploadBatch) Length

func (b *UploadBatch) Length() int

Length gets the number of files in a batch.

func (*UploadBatch) Size

func (b *UploadBatch) Size() int64

Size of the batch in bytes.

func (*UploadBatch) Upload

func (b *UploadBatch) Upload(ctx context.Context) error

Upload the files in a batch. Closes all readers.

Jump to

Keyboard shortcuts

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