backends

package
v0.0.0-...-4528f7a Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileTooLarge = errors.New("file too large")
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Put(r io.Reader) (string, error)
	Get(key string, w io.Writer) error
}

type FileBackend

type FileBackend struct {

	// root is the root directory where files are stored
	Root string `yaml:"root"`

	// maxSize is the maximum size of a submission
	MaxSize int64 `yaml:"max_size"`
	// contains filtered or unexported fields
}

func DefaultFileBackend

func DefaultFileBackend(root string) (*FileBackend, error)

Returns a file backend with sensible defaults

func NewFileBackend

func NewFileBackend(root string, maxSize int64, pathGen PathGenFunc) (*FileBackend, error)

func (*FileBackend) Get

func (f *FileBackend) Get(path string, w io.Writer) error

Get writes the contents of the file at key to w

func (*FileBackend) Put

func (f *FileBackend) Put(r io.Reader) (string, error)

Put stores the contents of r in a file and returns the generated path to the file

type MemoryBackend

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

MemoryBackend is a backend that stores files in memory

func NewMemoryBackend

func NewMemoryBackend() *MemoryBackend

func (*MemoryBackend) Get

func (m *MemoryBackend) Get(key string, w io.Writer) error

Get writes the contents of the file at key to w

func (*MemoryBackend) Put

func (m *MemoryBackend) Put(r io.Reader) (string, error)

Put stores the contents of r in memory and returns the key The key is the first 4 bytes of the SHA256 hash of the contents

type PathGenFunc

type PathGenFunc func() string

type PgxBackend

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

PgxBackend is a backend that stores pastes in a PostgreSQL database. It uses pgx as the driver.

func NewPostgresBackend

func NewPostgresBackend(ctx context.Context, connString string, pgf PathGenFunc, createTables bool) (*PgxBackend, error)

NewPostgresBackend creates a new PostgresBackend. If createTables is true, the necessary tables will be created if they do not exist.

func (*PgxBackend) Get

func (b *PgxBackend) Get(key string, w io.Writer) error

func (*PgxBackend) Put

func (b *PgxBackend) Put(r io.Reader) (string, error)

type RedisBackend

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

func NewRedisBackend

func NewRedisBackend(ctx context.Context, pgf PathGenFunc, client *redis.Client) *RedisBackend

func (*RedisBackend) Get

func (b *RedisBackend) Get(key string, w io.Writer) error

Get writes the contents of the file at key to w. If the key does not exist, Get should return nil.

Note that the value is read into memory before being written to w.

func (*RedisBackend) Put

func (b *RedisBackend) Put(r io.Reader) (string, error)

Put stores the contents of r in memory and returns the key. Note that r will be read into memory before being stored.

type S3Backend

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

func NewS3Backend

func NewS3Backend(ctx context.Context, pgf PathGenFunc, bucket string, client *s3.Client) *S3Backend

func (*S3Backend) Get

func (b *S3Backend) Get(key string, w io.Writer) error

Get writes the contents of the file at key to w. If the key does not exist, Get should return nil.

Note that the value is read into memory before being written to w.

func (*S3Backend) Put

func (b *S3Backend) Put(r io.Reader) (string, error)

Put stores the contents of r in memory and returns the key.

type SQLiteBackend

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

func NewSQLiteBackend

func NewSQLiteBackend(db *sql.DB, pgf PathGenFunc, createTables bool) (*SQLiteBackend, error)

func (*SQLiteBackend) Get

func (b *SQLiteBackend) Get(key string, w io.Writer) error

func (*SQLiteBackend) Put

func (b *SQLiteBackend) Put(r io.Reader) (string, error)

Jump to

Keyboard shortcuts

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