fileserver

package
v0.0.3-beta.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFileDownloader

func RegisterFileDownloader(route httpx.Router, storage storage.Storage, options ...DownloaderOption)

RegisterFileDownloader registers a Gin route handler for file downloads from storage. It handles GET requests to serve files directly from the storage backend.

func RegisterFormFileUploader

func RegisterFormFileUploader(route httpx.Router, storage storage.Storage, keyBuilder FileKeyBuilder, options ...UploadOption)

RegisterFormFileUploader registers a Gin route handler for form-based file uploads. It accepts multipart form uploads and stores files using the provided key builder.

Types

type Config

type Config struct {
	PublicBase string `json:"public_base" yaml:"public_base"`
	PutPrefix  string `json:"put_prefix" yaml:"put_prefix"`
}

Config holds the configuration for S3 adapter operations.

type DownloaderOption

type DownloaderOption func(o *downloaderOptions)

DownloaderOption configures file download behavior.

func WithCacheControl

func WithCacheControl(maxAge uint64) DownloaderOption

WithCacheControl sets the Cache-Control header for downloaded files.

type FileKeyBuilder

type FileKeyBuilder func(ctx httpx.Context, filename string) string

FileKeyBuilder generates storage keys from HTTP context and filenames. This allows customization of how uploaded files are named and organized.

type S3Adapter

type S3Adapter struct {
	storage.Storage
	// contains filtered or unexported fields
}

S3Adapter provides a caching layer and upload token generation for S3-compatible storage. It extends a base storage implementation with temporary upload URL generation capabilities.

func NewS3Adapter

func NewS3Adapter(config *Config, cache cache.ByteCache, store storage.Storage) *S3Adapter

NewS3Adapter creates a new S3 adapter with caching and upload token generation. It wraps an existing storage implementation to add temporary upload URL functionality.

func (*S3Adapter) GenerateUploadToken

func (a *S3Adapter) GenerateUploadToken(ctx context.Context, fileName string, dir string, nameBuilder func(filename string, dir ...string) string) ([3]string, error)

GenerateUploadToken creates a temporary upload URL and token for client-side uploads. Returns the upload URL, final storage key, and public access URL.

func (*S3Adapter) RegisterFileDownloader

func (a *S3Adapter) RegisterFileDownloader(route httpx.Router, options ...DownloaderOption)

func (*S3Adapter) RegisterPutFileUploader

func (a *S3Adapter) RegisterPutFileUploader(route httpx.Router, options ...UploadOption)

RegisterPutFileUploader registers a Gin route handler for PUT-based file uploads. It handles temporary upload URLs generated by GenerateUploadToken and stores files using the original filename mapped from the temporary key.

type UploadOption

type UploadOption func(*uploadOptions)

UploadOption configures file upload behavior and response handling.

Jump to

Keyboard shortcuts

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