storage

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: Apache-2.0 Imports: 11 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 instanz 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 etag>/<next two letters of etag>/<rest of etag>/<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(username string, key string) []byte

Get loads the image from the file system.

func (*FileSystem) Set

func (s *FileSystem) Set(username string, key string, img []byte) error

Set writes the image to the file system.

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(username string, key string) []byte

Get loads the thumbnail from memory.

func (InMemory) Set

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

Set stores the thumbnail in memory.

type Request

type Request struct {
	ETag       string
	Types      []string
	Resolution resolution.Resolution
}

Request combines different attributes needed for storage operations.

type Storage

type Storage interface {
	Get(string, string) []byte
	Set(string, 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