Documentation
¶
Index ¶
- func CreateMinioClient(ctx context.Context, config Config, log *zap.Logger) (*minio.Client, error)
- func DeleteRecursive(ctx context.Context, s Storage, prefix string) error
- func DeleteSimple(ctx context.Context, s Storage, key string) error
- func DownloadFile(c *fiber.Ctx, s Storage, key string) error
- func DownloadToBytes(ctx context.Context, s Storage, key string) ([]byte, error)
- func FileExists(ctx context.Context, s Storage, key string) (bool, error)
- func GenerateKey(prefix, filename string) string
- func GenerateUniqueKey(prefix, filename string) string
- func GetPublicURL(ctx context.Context, s Storage, key string) (string, error)
- func GetTemporaryURL(ctx context.Context, s Storage, key string, validFor time.Duration) (string, error)
- func ProxyToFiber(c *fiber.Ctx, s Storage, key string, opts *ProxyOptions) error
- func ServeFile(c *fiber.Ctx, s Storage, key string) error
- func Start(lc fx.Lifecycle, storage Storage)
- func StreamToFiber(c *fiber.Ctx, s Storage, key string) error
- type Config
- type DeleteOptions
- type DownloadOptions
- type ListOptions
- type ListResult
- type Metadata
- func CopyFile(ctx context.Context, s Storage, srcKey, destKey string) (*Metadata, error)
- func GetFileInfo(ctx context.Context, s Storage, key string) (*Metadata, error)
- func ListAll(ctx context.Context, s Storage) ([]*Metadata, error)
- func ListByPrefix(ctx context.Context, s Storage, prefix string) ([]*Metadata, error)
- func UploadBytes(ctx context.Context, s Storage, key string, data []byte, contentType string) (*Metadata, error)
- func UploadFile(ctx context.Context, s Storage, key string, reader io.Reader, ...) (*Metadata, error)
- func UploadMultipartSimple(ctx context.Context, s Storage, key string, fileHeader *multipart.FileHeader) (*Metadata, error)
- func UploadPublic(ctx context.Context, s Storage, key string, reader io.Reader, ...) (*Metadata, error)
- func UploadWithCache(ctx context.Context, s Storage, key string, reader io.Reader, ...) (*Metadata, error)
- func UploadWithMetadata(ctx context.Context, s Storage, key string, reader io.Reader, ...) (*Metadata, error)
- type MinioStorage
- func (s *MinioStorage) Delete(ctx context.Context, key string, opts *DeleteOptions) error
- func (s *MinioStorage) Download(ctx context.Context, key string, opts *DownloadOptions) (io.ReadCloser, error)
- func (s *MinioStorage) Exists(ctx context.Context, key string) (bool, error)
- func (s *MinioStorage) GetMetadata(ctx context.Context, key string) (*Metadata, error)
- func (s *MinioStorage) GetSignedURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (s *MinioStorage) GetURL(ctx context.Context, key string) (string, error)
- func (s *MinioStorage) List(ctx context.Context, opts *ListOptions) (*ListResult, error)
- func (s *MinioStorage) Start(ctx context.Context) error
- func (s *MinioStorage) Stop(context.Context) error
- func (s *MinioStorage) Upload(ctx context.Context, reader io.Reader, opts *UploadOptions) (*Metadata, error)
- func (s *MinioStorage) UploadMultipart(ctx context.Context, fileHeader *multipart.FileHeader, opts *UploadOptions) (*Metadata, error)
- type ProxyOptions
- type Storage
- type UploadOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateMinioClient ¶
func DeleteRecursive ¶
DeleteRecursive deletes all files with the given prefix
func DeleteSimple ¶
DeleteSimple deletes a single file
func DownloadFile ¶
DownloadFile forces a file download through Fiber
func DownloadToBytes ¶
DownloadToBytes downloads a file and returns it as bytes
func FileExists ¶
FileExists checks if a file exists in storage
func GenerateKey ¶
GenerateKey generates a unique storage key from a filename
func GenerateUniqueKey ¶
GenerateUniqueKey generates a unique key with UUID-like identifier
func GetPublicURL ¶
GetPublicURL returns a permanent public URL for a file
func GetTemporaryURL ¶
func GetTemporaryURL(ctx context.Context, s Storage, key string, validFor time.Duration) (string, error)
GetTemporaryURL generates a temporary signed URL valid for the specified duration
func ProxyToFiber ¶
ProxyToFiber proxies a file with support for range requests and caching
Types ¶
type Config ¶
type Config struct {
PublicEndpoint string `mapstructure:"public_endpoint" yaml:"public_endpoint"`
Endpoint string `mapstructure:"endpoint" yaml:"endpoint"`
AccessKeyID string `mapstructure:"access_key_id" yaml:"access_key_id"`
SecretAccessKey string `mapstructure:"secret_access_key" yaml:"secret_access_key"`
BucketName string `mapstructure:"bucket_name" yaml:"bucket_name"`
UseSSL bool `mapstructure:"use_ssl" yaml:"use_ssl"`
}
type DeleteOptions ¶
type DeleteOptions struct {
// Recursive deletes all files with matching prefix
Recursive bool
}
DeleteOptions configures file deletion behavior
func DefaultDeleteOptions ¶
func DefaultDeleteOptions() *DeleteOptions
Helper function for delete options
type DownloadOptions ¶
type DownloadOptions struct {
// Range specifies byte range (e.g., "bytes=0-1023")
Range string
// IfModifiedSince for conditional downloads
IfModifiedSince *time.Time
}
DownloadOptions configures file download behavior
func DefaultDownloadOptions ¶
func DefaultDownloadOptions() *DownloadOptions
Helper function for download options
type ListOptions ¶
type ListOptions struct {
// Prefix filters by key prefix
Prefix string
// MaxResults limits number of results
MaxResults int
// ContinuationToken for pagination
ContinuationToken string
}
ListOptions configures file listing behavior
type ListResult ¶
ListResult contains list operation results
type Metadata ¶
type Metadata struct {
Key string // Storage key/path
FileName string // Original filename
ContentType string // MIME type
URL string // Access URL
Size int64 // File size in bytes
ETag string // Entity tag for caching
Width int // Image width (0 if not applicable)
Height int // Image height (0 if not applicable)
ModTime time.Time // Last modified time
Custom map[string]string // Custom metadata
}
Metadata contains information about an uploaded/stored file
func GetFileInfo ¶
GetFileInfo retrieves file information without downloading
func ListByPrefix ¶
ListByPrefix lists all files with a given prefix
func UploadBytes ¶
func UploadBytes(ctx context.Context, s Storage, key string, data []byte, contentType string) (*Metadata, error)
UploadBytes uploads byte data as a file
func UploadFile ¶
func UploadFile(ctx context.Context, s Storage, key string, reader io.Reader, contentType string) (*Metadata, error)
UploadFile is a convenience function to upload a file with minimal configuration
func UploadMultipartSimple ¶
func UploadMultipartSimple(ctx context.Context, s Storage, key string, fileHeader *multipart.FileHeader) (*Metadata, error)
UploadMultipartSimple uploads a multipart file with a simple key
func UploadPublic ¶
func UploadPublic(ctx context.Context, s Storage, key string, reader io.Reader, contentType string) (*Metadata, error)
UploadPublic uploads a file and makes it publicly accessible
type MinioStorage ¶
func (*MinioStorage) Delete ¶
func (s *MinioStorage) Delete(ctx context.Context, key string, opts *DeleteOptions) error
Delete removes a file
func (*MinioStorage) Download ¶
func (s *MinioStorage) Download(ctx context.Context, key string, opts *DownloadOptions) (io.ReadCloser, error)
Download retrieves a file
func (*MinioStorage) GetMetadata ¶
GetMetadata retrieves file metadata without downloading
func (*MinioStorage) GetSignedURL ¶
func (s *MinioStorage) GetSignedURL(ctx context.Context, key string, expiry time.Duration) (string, error)
GetSignedURL returns a temporary signed URL
func (*MinioStorage) List ¶
func (s *MinioStorage) List(ctx context.Context, opts *ListOptions) (*ListResult, error)
List lists files matching criteria
func (*MinioStorage) Upload ¶
func (s *MinioStorage) Upload(ctx context.Context, reader io.Reader, opts *UploadOptions) (*Metadata, error)
Upload uploads a file from an io.Reader
func (*MinioStorage) UploadMultipart ¶
func (s *MinioStorage) UploadMultipart(ctx context.Context, fileHeader *multipart.FileHeader, opts *UploadOptions) (*Metadata, error)
UploadMultipart uploads from a multipart form file
type ProxyOptions ¶
type ProxyOptions struct {
// EnableCaching enables ETag-based caching
EnableCaching bool
// EnableRangeRequests enables HTTP range request support
EnableRangeRequests bool
// CacheControl sets the Cache-Control header
CacheControl string
// Attachment forces download instead of inline display
Attachment bool
}
ProxyOptions configures file proxying behavior
func DefaultProxyOptions ¶
func DefaultProxyOptions() *ProxyOptions
DefaultProxyOptions returns sensible defaults for proxying
type Storage ¶
type Storage interface {
lifecycle.StartStoper
logging.Logger
// Upload uploads a file from an io.Reader
Upload(ctx context.Context, reader io.Reader, opts *UploadOptions) (*Metadata, error)
// UploadMultipart uploads from a multipart form file (convenience method)
UploadMultipart(ctx context.Context, fileHeader *multipart.FileHeader, opts *UploadOptions) (*Metadata, error)
// Download retrieves a file
Download(ctx context.Context, key string, opts *DownloadOptions) (io.ReadCloser, error)
// Delete removes a file
Delete(ctx context.Context, key string, opts *DeleteOptions) error
// Exists checks if a file exists
Exists(ctx context.Context, key string) (bool, error)
// GetMetadata retrieves file metadata without downloading
GetMetadata(ctx context.Context, key string) (*Metadata, error)
// List lists files matching criteria
List(ctx context.Context, opts *ListOptions) (*ListResult, error)
// GetURL returns a public URL for accessing the file
GetURL(ctx context.Context, key string) (string, error)
// GetSignedURL returns a temporary signed URL (if supported)
GetSignedURL(ctx context.Context, key string, expiry time.Duration) (string, error)
}
Storage is the unified interface for all storage operations
func NewMinioStorage ¶
type UploadOptions ¶
type UploadOptions struct {
// Key is the storage path/key. If empty, auto-generated from filename
Key string
// ContentType overrides auto-detection
ContentType string
// Metadata allows custom key-value pairs
Metadata map[string]string
// ExtractImageDimensions automatically extracts width/height for images
ExtractImageDimensions bool
// CacheControl sets cache control headers
CacheControl string
// Public makes the file publicly accessible (if supported)
Public bool
}
UploadOptions configures file upload behavior
func DefaultUploadOptions ¶
func DefaultUploadOptions(key string) *UploadOptions
Helper function to create default upload options