upload

package
v0.0.0-...-cf55a68 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOpID

func NewOpID(ctx context.Context) (int64, error)

NewOpID returns new unique upload operation ID.

func UnwrapOpID

func UnwrapOpID(ctx context.Context, token string, caller identity.Identity) (int64, error)

UnwrapOpID extracts upload operation ID from a HMAC-protected string.

func WrapOpID

func WrapOpID(ctx context.Context, id int64, caller identity.Identity) (string, error)

WrapOpID returns HMAC-protected string that embeds upload operation ID.

The string is bound to the given caller, i.e UnwrapOpID will correctly validate HMAC only if it receives the exact same caller.

Types

type Operation

type Operation struct {
	ID int64 `gae:"$id"`

	Status api.UploadStatus
	Error  string `gae:",noindex"` // error message if the verification failed

	TempGSPath string `gae:",noindex"` // the GS path to where the client uploads
	UploadURL  string `gae:",noindex"` // resumable upload URL

	HashAlgo  api.HashAlgo // the algo to use to verify the uploaded content
	HexDigest string       // the expected content digest or "" if not known

	CreatedBy identity.Identity // who initiated the upload, FYI
	CreatedTS time.Time         // when the upload was initiated, FYI
	UpdatedTS time.Time         // last time this entity was saved, FYI
	// contains filtered or unexported fields
}

Operation is a datastore entity that represents an upload.

func (*Operation) Advance

func (op *Operation) Advance(ctx context.Context, cb func(context.Context, *Operation) error) (*Operation, error)

Advance transactionally updates the entity (by calling the callback) if its Status in the datastore is still same as op.Status.

If the entity in the datastore has different Status, silently skips calling the callback. It means the entity has been updated concurrently. This works because all Operation mutations actually switch statuses and the Operation state machine can "roll" only in one direction.

Returns the most recent state of the operation (whether it was mutated just now by the callback or not). 'op' itself is kept intact.

Returns only transient errors. All callback errors are tagged as transient as well.

func (*Operation) ToProto

func (op *Operation) ToProto(wrappedID string) *api.UploadOperation

ToProto constructs UploadOperation proto message.

The caller must prepare the ID in advance using WrapOpID.

Jump to

Keyboard shortcuts

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