storage

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

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

FileSystem represents a storage for the thumbnails using the local file system.

func NewFileSystemStorage

func NewFileSystemStorage(cfg config.FileSystemStorage, logger log.Logger) FileSystem

NewFileSystemStorage creates a new instance of FileSystem

func (FileSystem) BuildKey

func (s FileSystem) BuildKey(r Request) string

BuildKey generate the unique key for a thumbnail. The key is structure as follows:

<first two letters of checksum>/<next two letters of checksum>/<rest of checksum>/<width>x<height>.<filetype>

e.g. 97/9f/4c8db98f7b82e768ef478d3c8612/500x300.png

The key also represents the path to the thumbnail in the filesystem under the configured root directory.

func (FileSystem) Get

func (s FileSystem) Get(key string) ([]byte, error)

func (FileSystem) Put

func (s FileSystem) Put(key string, img []byte) error

func (FileSystem) Stat

func (s FileSystem) Stat(key string) bool

type InMemory

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

InMemory represents an in memory storage for thumbnails Can be used during development

func NewInMemoryStorage

func NewInMemoryStorage() InMemory

NewInMemoryStorage creates a new InMemory instance.

func (InMemory) BuildKey

func (s InMemory) BuildKey(r Request) string

BuildKey generates a unique key to store and retrieve the thumbnail.

func (InMemory) Get

func (s InMemory) Get(key string) ([]byte, error)

Get loads the thumbnail from memory.

func (InMemory) Put

func (s InMemory) Put(key string, thumbnail []byte) error

Set stores the thumbnail in memory.

func (InMemory) Stat

func (s InMemory) Stat(key string) bool

type Request

type Request struct {
	// The checksum of the source file
	// Will be used to determine if a thumbnail exists
	Checksum string
	// Types provided by the encoder.
	// Contains the mimetypes of the thumbnail.
	// In case of jpg/jpeg it will contain both.
	Types []string
	// The resolution of the thumbnail
	Resolution image.Rectangle
}

Request combines different attributes needed for storage operations.

type Storage

type Storage interface {
	Stat(string) bool
	Get(string) ([]byte, error)
	Put(string, []byte) error
	BuildKey(Request) string
}

Storage defines the interface for a thumbnail store.

Jump to

Keyboard shortcuts

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