Documentation
¶
Index ¶
- type Config
- type FileMetadata
- type HTTPHandler
- func (h *HTTPHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (h *HTTPHandler) Download(w http.ResponseWriter, r *http.Request)
- func (h *HTTPHandler) DownloadContent(w http.ResponseWriter, r *http.Request)
- func (h *HTTPHandler) Upload(w http.ResponseWriter, r *http.Request)
- func (h *HTTPHandler) UploadContentLocal(w http.ResponseWriter, r *http.Request)
- type Service
- func (s *Service) Delete(ctx context.Context, key string) error
- func (s *Service) Download(ctx context.Context, key string) (io.ReadCloser, string, error)
- func (s *Service) GetDownloadURL(ctx context.Context, key string) (string, error)
- func (s *Service) Upload(ctx context.Context, filename string, size int64, mime string) (*FileMetadata, error)
- type StorageDriver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type FileMetadata ¶
type FileMetadata struct {
ID string `json:"id"`
Name string `json:"name"`
Key string `json:"key"`
URL string `json:"url,omitempty"`
UploadURL string `json:"upload_url,omitempty"`
Size int64 `json:"size"`
MimeType string `json:"mime_type"`
}
FileMetadata represents the metadata of an uploaded file
type HTTPHandler ¶
type HTTPHandler struct {
Service *Service
}
func NewHTTPHandler ¶
func NewHTTPHandler(service *Service) *HTTPHandler
func (*HTTPHandler) Delete ¶
func (h *HTTPHandler) Delete(w http.ResponseWriter, r *http.Request)
func (*HTTPHandler) Download ¶
func (h *HTTPHandler) Download(w http.ResponseWriter, r *http.Request)
func (*HTTPHandler) DownloadContent ¶
func (h *HTTPHandler) DownloadContent(w http.ResponseWriter, r *http.Request)
DownloadContent streams the file body directly from the local filesystem driver. It is intended only for local development when using LocalFSDriver; in non-local environments (e.g. S3) callers should use GetDownloadURL and presigned URLs instead.
func (*HTTPHandler) Upload ¶
func (h *HTTPHandler) Upload(w http.ResponseWriter, r *http.Request)
func (*HTTPHandler) UploadContentLocal ¶
func (h *HTTPHandler) UploadContentLocal(w http.ResponseWriter, r *http.Request)
UploadContentLocal acts as a mock S3 bucket for local development. It accepts a PUT request with the raw file body.
type Service ¶
type Service struct {
Driver StorageDriver
}
Service coordinates file storage operations and manages metadata
func NewService ¶
func NewService(driver StorageDriver) *Service
func (*Service) GetDownloadURL ¶
GetDownloadURL generates a time-limited or presigned URL for the given key
type StorageDriver ¶
type StorageDriver interface {
// Save writes the content to the storage and returns a unique identifier (key/path)
Save(ctx context.Context, key string, body io.Reader, contentType string) error
// Get returns a ReadCloser to stream the file back and its content type
Get(ctx context.Context, key string) (io.ReadCloser, string, error)
// Delete removes the file
Delete(ctx context.Context, key string) error
// GetDownloadURL returns a presigned or time-limited URL for downloading
GetDownloadURL(ctx context.Context, key string) (string, error)
// GetUploadURL returns a presigned URL for uploading a file directly to storage
GetUploadURL(ctx context.Context, key string, contentType string, maxSizeBytes int64) (string, error)
}
StorageDriver defines how we interact with the binary storage
func NewStorageFromConfig ¶
func NewStorageFromConfig(ctx context.Context, cfg Config) (StorageDriver, error)
NewStorageFromConfig creates a storage instance based on the provided configuration.