proxy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2014 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package data provides common shared data structures for imageproxy.

Package proxy provides the image proxy.

Package transform handles image transformation such as resizing.

Index

Constants

This section is empty.

Variables

View Source
var NopCache = new(nopCache)

NopCache provides a no-op cache implementation that doesn't actually cache anything.

Functions

func Transform added in v0.2.0

func Transform(img []byte, opt *Options) ([]byte, error)

Transform the provided image.

Types

type Cache

type Cache interface {
	// Get retrieves the cached data for the provided key.
	Get(key string) (data []byte, ok bool)

	// Set caches the provided data.
	Set(key string, data []byte)

	// Delete deletes the cached data at the specified key.
	Delete(key string)
}

The Cache interface defines a cache for storing arbitrary data. The interface is designed to align with httpcache.Cache.

type Options added in v0.2.0

type Options struct {
	Width  float64 // requested width, in pixels
	Height float64 // requested height, in pixels

	// If true, resize the image to fit in the specified dimensions.  Image
	// will not be cropped, and aspect ratio will be maintained.
	Fit bool

	// Rotate image the specified degrees counter-clockwise.  Valid values are 90, 180, 270.
	Rotate int

	FlipVertical   bool
	FlipHorizontal bool
}

Options specifies transformations that can be performed on a requested image.

func ParseOptions added in v0.2.0

func ParseOptions(str string) *Options

func (Options) String added in v0.2.0

func (o Options) String() string

type Proxy

type Proxy struct {
	Client *http.Client // client used to fetch remote URLs
	Cache  Cache

	// Whitelist specifies a list of remote hosts that images can be proxied from.  An empty list means all hosts are allowed.
	Whitelist []string

	MaxWidth  int
	MaxHeight int
}

Proxy serves image requests.

func NewProxy

func NewProxy(transport http.RoundTripper, cache Cache) *Proxy

NewProxy constructs a new proxy. The provided http Client will be used to fetch remote URLs. If nil is provided, http.DefaultClient will be used.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles image requests.

type Request added in v0.2.0

type Request struct {
	URL     *url.URL // URL of the image to proxy
	Options *Options // Image transformation to perform
}

func NewRequest

func NewRequest(r *http.Request) (*Request, error)

NewRequest parses an http.Request into an image request.

type TransformingTransport added in v0.2.0

type TransformingTransport struct {
	// Transport is used to satisfy non-transform requests (those that do not include a URL fragment)
	Transport http.RoundTripper

	// Client is used to fetch images to be resized.
	Client *http.Client
}

TransformingTransport is an implementation of http.RoundTripper that optionally transforms images using the options specified in the request URL fragment.

func (*TransformingTransport) RoundTrip added in v0.2.0

func (t *TransformingTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type URLError

type URLError struct {
	Message string
	URL     *url.URL
}

URLError reports a malformed URL error.

func (URLError) Error

func (e URLError) Error() string

Jump to

Keyboard shortcuts

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