storage

package
v0.9.18 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilesystemStore

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

FilesystemStore stores paste metadata and content on the local filesystem.

func NewFilesystemStore

func NewFilesystemStore(dataDir string) (*FilesystemStore, error)

NewFilesystemStore creates a FilesystemStore for the given data directory. If dataDir is empty it defaults to "./data". The directory is created if it does not exist.

func (*FilesystemStore) Close

func (fs *FilesystemStore) Close() error

func (*FilesystemStore) Delete

func (fs *FilesystemStore) Delete(id string) error

func (*FilesystemStore) Exists

func (fs *FilesystemStore) Exists(id string) (bool, error)

func (*FilesystemStore) Get

func (fs *FilesystemStore) Get(id string) (*models.Paste, error)

func (*FilesystemStore) GetContent

func (fs *FilesystemStore) GetContent(id string) ([]byte, error)

func (*FilesystemStore) GetContentPrefix added in v0.9.8

func (fs *FilesystemStore) GetContentPrefix(id string, n int64) ([]byte, error)

GetContentPrefix reads up to n bytes from the content file. If the file is smaller than n, it returns the full content.

func (*FilesystemStore) IncrementReadCount

func (fs *FilesystemStore) IncrementReadCount(id string) error

func (*FilesystemStore) StatContent added in v0.9.10

func (fs *FilesystemStore) StatContent(id string) (bool, int64, error)

StatContent reports whether content exists on disk and its size.

func (*FilesystemStore) Store

func (fs *FilesystemStore) Store(paste *models.Paste) error

Store saves the paste metadata (JSON) to local filesystem

func (*FilesystemStore) StoreContent

func (fs *FilesystemStore) StoreContent(id string, content []byte) error

type PasteStore

type PasteStore interface {
	// Store saves a paste to the storage backend
	Store(paste *models.Paste) error

	// Get retrieves a paste by its ID
	Get(id string) (*models.Paste, error)

	// Exists checks if a paste exists by its ID
	Exists(id string) (bool, error)

	// Delete removes a paste from storage
	Delete(id string) error

	// IncrementReadCount increments the read count for a paste
	IncrementReadCount(id string) error

	// Close closes the storage connection
	Close() error

	// StoreContent saves the raw content for a paste
	StoreContent(id string, content []byte) error

	// GetContent retrieves the raw content for a paste
	GetContent(id string) ([]byte, error)

	// GetContentPrefix retrieves up to n bytes of the raw content for a paste.
	// Implementations should return as many bytes as are available up to n.
	GetContentPrefix(id string, n int64) ([]byte, error)

	// StatContent reports whether content exists and its size. Implementations
	// should return (false, 0, nil) when the content does not exist.
	// This is used by handlers to perform early size checks without
	// retrieving the entire object.
	StatContent(id string) (exists bool, size int64, err error)
}

PasteStore defines the interface for paste storage backends

type S3Store

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

func NewS3Store

func NewS3Store(bucket, prefix string) (*S3Store, error)

NewS3Store creates a new S3Store instance

func (*S3Store) Close

func (s *S3Store) Close() error

func (*S3Store) Delete

func (s *S3Store) Delete(id string) error

func (*S3Store) Exists

func (s *S3Store) Exists(id string) (bool, error)

func (*S3Store) Get

func (s *S3Store) Get(id string) (*models.Paste, error)

func (*S3Store) GetContent

func (s *S3Store) GetContent(id string) ([]byte, error)

func (*S3Store) GetContentPrefix added in v0.9.8

func (s *S3Store) GetContentPrefix(id string, n int64) ([]byte, error)

GetContentPrefix retrieves up to n bytes from an S3 object using Range header.

func (*S3Store) IncrementReadCount

func (s *S3Store) IncrementReadCount(id string) error

func (*S3Store) StatContent added in v0.9.10

func (s *S3Store) StatContent(id string) (bool, int64, error)

StatContent checks if the object exists in S3 and returns its size.

func (*S3Store) Store

func (s *S3Store) Store(paste *models.Paste) error

func (*S3Store) StoreContent

func (s *S3Store) StoreContent(id string, content []byte) error

Jump to

Keyboard shortcuts

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