handler

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(storage Storage, cfg *Config) http.Handler

New constructs a new file-exchange handler.

It has the following routes: a) GET / - serve upload page c) POST / - handle upload, always sets X-Upload-Hash response header b) GET /{hash} - serve file

If cfg.AuthRead is provided, it demands HTTP Basic auth for read operations (GET-s). If cfg.AuthWrite is provided, it demands HTTP Basic auth for write operations (POST-s).

If cfg.Oneshot is enabled, the handler works in oneshot mode: uploaded file is removed after first successful (2xx) download. Note: this is protected only with cfg.AuthRead.

If cfg.Aliasing is enabled, files can be downloaded like /{hash}.{ext} or /{hash}/{filename}.

Types

type Config added in v0.0.6

type Config struct {
	AuthRead  map[string]string `split_words:"true"`
	AuthWrite map[string]string `split_words:"true"`
	Oneshot   bool              `default:"false"` // rm file after first successful serve
	Aliasing  bool              `default:"false"` // allow to alias file/ext on download (freeform)
}

Configig defines a file-exchange handler config.

type Storage

type Storage interface {
	Create(io.Reader) (string, error)
	Path(string) (string, error)
	Remove(string) error
}

Storage defines a file storage abstraction.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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