persist

package
v0.0.0-...-5a969d9 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Status

type Status int

Status indicates the status of an upload.

const (
	// Started is the status for active uploads.
	Started Status = iota
	// Completed is the status of uploads that completed successfully.
	Completed
	// TimedOut is the status for uploads that took longer than the allotted
	// time.
	TimedOut
	// Failed is the status for uploads that failed due to an unexpected error.
	Failed
)

func (Status) String

func (s Status) String() string

String returns a human-friendly description of the upload state.

type Store

type Store interface {
	// Load retrieves the upload with the given ID. Load should return nil, nil
	// if there is not upload with the given ID.
	Load(id string) (*Upload, error)

	// Save persists the given upload with the given ID.
	Save(id string, s *Upload) error
}

Store is an opinionated data store interface suitable for use together with a TUS server implementation.

func NewInMemory

func NewInMemory() Store

NewInMemory returns a store implementation that relies on a in-memory map to keep the server state. This means only one process can be exposed to the upload HTTP endpoint and that uploads won't survive process restarts. This implementation is thus probably not suitable for prodcution use.

type Upload

type Upload struct {
	// ID is a unique identifier for the upload.
	ID string
	// StartedAt is the creation timestamp for the upload.
	StartedAt time.Time
	// ExpiresAt is the upload expiration timestamp if any, the Zero
	// time.Time value otherwise.
	ExpiresAt time.Time
	// Status is the current upload status.
	Status Status
	// Length is the total length of the upload if known, nil otherwise.
	Length *int64
	// Offset is the count of bytes that have already been uploaded.
	Offset int64
	// Metadata is arbitrary pass-through data that can be used by clients to
	// attach information to the upload.
	Metadata string
}

Upload contains the information needed to manage an upload.

func (*Upload) Active

func (u *Upload) Active() bool

Active returns true if the upload has not completed, failed or timed out.

Jump to

Keyboard shortcuts

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