server

package
v0.0.0-...-3570e06 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	//ImageCacheDuration caching time for images
	ImageCacheDuration = 315360000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacheable

type Cacheable interface {
	CacheIdentifier() string
	LastModified() time.Time
	Data() ReadSeekCloser
	Name() string
}

Cacheable is an interface for caching

type Config

type Config struct {
	AllowedEntries []Entry `json:allowedEntries`
}

Config contains entries for possible image configurations

func NewConfigFromBytes

func NewConfigFromBytes(b []byte) (*Config, error)

NewConfigFromBytes generates a new config object by a byte stream

func NewConfigFromFile

func NewConfigFromFile(file string) (*Config, error)

NewConfigFromFile returns an Config object from a given file.

func (*Config) GetEntryByName

func (config *Config) GetEntryByName(name string) (*Entry, error)

GetEntryByName Returns an entry the the name.

type Configuration

type Configuration struct {
	Database   string
	FormatName string
	Filename   string
}

Configuration is a wrapper object for request parameters.

func CreateConfigurationFromVars

func CreateConfigurationFromVars(r *http.Request, vars map[string]string) (*Configuration, error)

CreateConfigurationFromVars validate all necessary request parameters

type Entry

type Entry struct {
	Name   string           `json:name`
	Width  int64            `json:width`
	Height int64            `json:height`
	Type   paint.ResizeType `json:type`
}

Entry is one allowed image configuration

type GridfsStorage

type GridfsStorage struct {
	Connection *mgo.Session
}

GridfsStorage will be made private

func (GridfsStorage) FindImageByParentFilename

func (g GridfsStorage) FindImageByParentFilename(namespace, filename string, entry *Entry) (Cacheable, error)

FindImageByParentFilename returns either the resized image that actually exists, or the original if entry is nil

func (GridfsStorage) FindImageByParentID

func (g GridfsStorage) FindImageByParentID(namespace, id string, entry *Entry) (Cacheable, error)

FindImageByParentID returns either the resized image that actually exists, or the original if entry is nil

func (GridfsStorage) IsValidID

func (g GridfsStorage) IsValidID(id string) bool

IsValidID will return true if id is a valid bson object id

func (GridfsStorage) StoreChildImage

func (g GridfsStorage) StoreChildImage(
	database,
	imageFormat string,
	reader io.Reader,
	imageWidth,
	imageHeight int,
	original Cacheable,
	entry *Entry,
) (Cacheable, error)

StoreChildImage will create a new image from source

type Identity

type Identity interface {
	ID() interface{}
}

Identity returns a unique identifer for its implementor

type MetaContainer

type MetaContainer interface {
	Meta() map[string]interface{}
}

MetaContainer is an optional interface that can be implemented to return optional metadata

type ReadSeekCloser

type ReadSeekCloser interface {
	io.ReadCloser
	io.Seeker
}

ReadSeekCloser implements io.ReadCloser and io.Seeker

type Server

type Server interface {
	Handler() http.Handler
}

Server interface for our server

func NewImageServer

func NewImageServer(config *Config, storage Storage) Server

NewImageServer returns a new image server

func NewImageServerWithNewRelic

func NewImageServerWithNewRelic(config *Config, storage Storage, licenseKey string) Server

NewImageServerWithNewRelic will return an image server with newrelic monitoring licenseKey must be your newrelic license key

type Storage

type Storage interface {
	StoreChildImage(database, imageFormat string, imageData io.Reader, imageWidth, imageHeight int, original Cacheable, entry *Entry) (Cacheable, error)
	FindImageByParentID(namespace, id string, entry *Entry) (Cacheable, error)
	FindImageByParentFilename(namespace, filename string, entry *Entry) (Cacheable, error)
	IsValidID(id string) bool
}

Storage interface can be implemented to use the image server with any backend you like

func NewGridfsStorage

func NewGridfsStorage(con *mgo.Session) (Storage, error)

NewGridfsStorage returns a new gridfs storage provider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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