Help us shape the future of Go! Take the 2026 Go Developer Survey

upload

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package upload owns request-scoped temporary files behind typed HTTP handles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

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

Batch owns all temporary files and readers for one request. Close waits for active captures/reads, closes readers, and removes only owned files. No recursive deletion or client-provided path participates in cleanup.

func New

func New(ctx context.Context, config Config) (*Batch, error)

func (*Batch) Capture

func (b *Batch) Capture(ctx context.Context, source io.Reader, name, declaredType string) (result File, err error)

Capture stores bytes with a fixed scratch buffer. Limits account for attempted writes and file creation; failed attempts do not replenish the request budget. The caller still owns the incoming reader. No partial File is published.

func (*Batch) Close

func (b *Batch) Close() error

type CleanupError

type CleanupError struct{ Cause error }

CleanupError reports a failed local cleanup rather than misclassifying an incoming reader failure as the complete outcome. The cause remains private.

func (*CleanupError) Error

func (*CleanupError) Error() string

func (*CleanupError) Unwrap

func (e *CleanupError) Unwrap() error

type Config

type Config struct {
	TempDirectory          string
	MaxBytes, MaxFileBytes int64
	MaxFiles, MaxReaders   int
}

Config bounds capture bytes, created files and concurrently open readers. Empty TempDirectory uses the operating system's temporary directory.

func (Config) Validate

func (c Config) Validate() error

type File

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

File is an opaque handle to a fully captured request-owned upload. Its zero value is absent. Metadata remains readable after cleanup; Open does not.

func (File) ClientContentType

func (f File) ClientContentType() string

ClientContentType is untrusted metadata supplied by the client.

func (File) ContentType

func (f File) ContentType() string

ContentType is Go's bounded content sniff, not proof of a valid image/document.

func (File) Extension

func (f File) Extension() string

func (File) GoString

func (File) GoString() string

func (File) IsZero

func (f File) IsZero() bool

func (File) MarshalJSON

func (File) MarshalJSON() ([]byte, error)

func (File) Name

func (f File) Name() string

func (File) Open

func (f File) Open(ctx context.Context) (io.ReadSeekCloser, error)

Open returns a new reader at offset zero. The caller closes it after use; request cleanup also closes retained readers. Neither the temporary filename nor an unrestricted os.File is exposed. Both contexts govern every operation.

func (File) Size

func (f File) Size() int64

func (File) String

func (File) String() string

type Limit

type Limit uint8
const (
	TotalBytes Limit = iota + 1
	FileBytes
	Files
	Readers
)

type LimitError

type LimitError struct{ Kind Limit }

func (*LimitError) Error

func (*LimitError) Error() string

type ReadError

type ReadError struct{ Cause error }

ReadError distinguishes failed incoming bytes from local filesystem failures. Error formatting never invokes the underlying reader's error methods.

func (*ReadError) Error

func (*ReadError) Error() string

func (*ReadError) Unwrap

func (e *ReadError) Unwrap() error

type Reader

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

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

func (*Reader) String

func (*Reader) String() string

type Source

type Source interface {
	Open(context.Context) (io.ReadSeekCloser, error)
	Name() string
	ClientContentType() string
}

Source is the shared structural contract for a captured file that a feature can open. The caller owns the file; each operation closes the reader it opens. Name and ClientContentType are untrusted display/type hints.

Jump to

Keyboard shortcuts

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