fs

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: MIT Imports: 8 Imported by: 0

README

File System Storage Backend

This package provides a file system implementation of the storage.Backend interface for the Simple Content Management System.

Overview

The file system storage backend stores content directly on the local file system. It's a simple and efficient storage solution for single-server deployments or development environments.

Configuration

The file system storage backend supports the following configuration options:

  1. Base Directory: The directory where files will be stored

    • This can be an absolute path or a relative path
    • The directory will be created if it doesn't exist
    • Default: ./data/storage
  2. URL Prefix: An optional URL prefix for download/upload URLs

    • If provided, the backend will return URLs for upload/download operations
    • If not provided, direct upload/download will be required
    • Default: empty (direct access)

Usage

Initialization
import (
    "github.com/tendant/simple-content/pkg/storage/fs"
)

// Create a new file system backend
config := fs.Config{
    BaseDir:   "./data/storage",
    URLPrefix: "http://localhost:8080",
}
fsBackend, err := fs.NewFSBackend(config)
if err != nil {
    log.Fatalf("Failed to initialize file system storage: %v", err)
}
Registration

Register the file system backend with the object service:

// Register the file system backend with the object service
objectService.RegisterBackend("fs", fsBackend)

// Create a storage backend record in the database
storageBackendService.CreateStorageBackend(
    ctx,
    "fs-default",
    "fs",
    map[string]interface{}{
        "base_dir": config.BaseDir,
    },
)
Storage Structure

Files are stored in the base directory with the object key as the path. For example, if the base directory is ./data/storage and the object key is content/123/file.txt, the file will be stored at ./data/storage/content/123/file.txt.

Limitations

  1. Scalability: Not suitable for distributed deployments
  2. Backup: Requires external backup solutions
  3. URL Access: Requires additional configuration for HTTP access to files
  4. Permissions: May require careful management of file system permissions

Benefits

  1. Simplicity: Easy to set up and understand
  2. Performance: Fast local access to files
  3. Debugging: Easy to inspect stored files directly on the file system
  4. No External Dependencies: Works without requiring external services
  5. Persistence: Data persists across application restarts

Documentation

Overview

Deprecated: This package is deprecated as of 2025-10-01 and will be removed in 3 months. Please migrate to github.com/tendant/simple-content/pkg/simplecontent/storage/fs which provides:

  • BlobStore interface implementation
  • Better error handling
  • Presigned URL support
  • Git-like object key organization

See MIGRATION_FROM_LEGACY.md for migration guide.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFSBackend

func NewFSBackend(config Config) (storage.Backend, error)

NewFSBackend creates a new file system storage backend

Types

type Config

type Config struct {
	BaseDir   string // Base directory for storing files
	URLPrefix string // Optional URL prefix for download/upload URLs
}

Config options for the file system backend

type FSBackend

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

FSBackend is a file system implementation of the storage.Backend interface

func (*FSBackend) Delete

func (b *FSBackend) Delete(ctx context.Context, objectKey string) error

Delete deletes content from the file system

func (*FSBackend) Download

func (b *FSBackend) Download(ctx context.Context, objectKey string) (io.ReadCloser, error)

Download downloads content directly from the file system

func (*FSBackend) GetDownloadURL

func (b *FSBackend) GetDownloadURL(ctx context.Context, objectKey string, downloadFilename string) (string, error)

GetDownloadURL returns a URL for downloading content

func (*FSBackend) GetObjectMeta

func (b *FSBackend) GetObjectMeta(ctx context.Context, objectKey string) (*storage.ObjectMeta, error)

GetObjectMeta retrieves metadata for an object in the file system

func (*FSBackend) GetPreviewURL

func (b *FSBackend) GetPreviewURL(ctx context.Context, objectKey string) (string, error)

GetReviewURL returns a URL for reviewing content

func (*FSBackend) GetUploadURL

func (b *FSBackend) GetUploadURL(ctx context.Context, objectKey string) (string, error)

GetUploadURL returns a URL for uploading content For file system, this could be a local file:// URL or an API endpoint

func (*FSBackend) Upload

func (b *FSBackend) Upload(ctx context.Context, objectKey string, reader io.Reader) error

Upload uploads content directly to the file system

func (*FSBackend) UploadWithParams added in v0.0.11

func (b *FSBackend) UploadWithParams(ctx context.Context, reader io.Reader, params storage.UploadParams) error

Jump to

Keyboard shortcuts

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