halfshell

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2014 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const STARTUP_TEMPLATE_STRING = `` /* 505-byte string literal not displayed */

Variables

View Source
var BlankImage = &Image{
	Bytes:    make([]byte, 0),
	MimeType: "",
}

Functions

func RegisterSource

func RegisterSource(sourceType ImageSourceType, factory ImageSourceFactoryFunction)

Types

type Config

type Config struct {
	ServerConfig *ServerConfig
	RouteConfigs []*RouteConfig
}

Config is the primary configuration of Halfshell. It contains the server configuration as well as a list of route configurations.

func NewConfigFromFile

func NewConfigFromFile(filepath string) *Config

Parses a JSON configuration file and returns a pointer to a new Config object.

type FileSystemImageSource added in v0.1.1

type FileSystemImageSource struct {
	Config *SourceConfig
	Logger *Logger
}

func (*FileSystemImageSource) GetImage added in v0.1.1

func (s *FileSystemImageSource) GetImage(request *ImageSourceOptions) *Image

type Halfshell

type Halfshell struct {
	Pid    int
	Config *Config
	Routes []*Route
	Server *Server
	Logger *Logger
}

Halfshell is the primary struct of the program. It holds onto the configuration, the HTTP server, and all the routes.

func NewWithConfig

func NewWithConfig(config *Config) *Halfshell

Create a new Halfshell instance from an instance of Config.

func (*Halfshell) Run

func (h *Halfshell) Run()

Start the Halfshell program. Performs global (de)initialization, and starts the HTTP server.

type HalfshellRequest

type HalfshellRequest struct {
	*http.Request
	Timestamp        time.Time
	Route            *Route
	SourceOptions    *ImageSourceOptions
	ProcessorOptions *ImageProcessorOptions
}

type HalfshellResponseWriter

type HalfshellResponseWriter struct {
	Status int
	Size   int
	// contains filtered or unexported fields
}

HalfshellResponseWriter is a wrapper around http.ResponseWriter that provides access to the response status and size after they have been set.

func (*HalfshellResponseWriter) SetHeader

func (hw *HalfshellResponseWriter) SetHeader(name, value string)

Sets the value for a response header.

func (*HalfshellResponseWriter) Write

func (hw *HalfshellResponseWriter) Write(data []byte) (int, error)

Writes data the output stream.

func (*HalfshellResponseWriter) WriteError

func (hw *HalfshellResponseWriter) WriteError(message string, status int)

Writes an error response.

func (*HalfshellResponseWriter) WriteHeader

func (hw *HalfshellResponseWriter) WriteHeader(status int)

Forwards to http.ResponseWriter's WriteHeader method.

func (*HalfshellResponseWriter) WriteImage

func (hw *HalfshellResponseWriter) WriteImage(image *Image)

Writes an image to the output stream and sets the appropriate headers.

type Image

type Image struct {
	Bytes    []byte
	MimeType string
}

Image contains a byte array of the image data and its MIME type. TODO: See if we can use the std library's Image type without incurring the hit of extra copying.

func NewImageFromFile added in v0.1.1

func NewImageFromFile(file *os.File) (*Image, error)

Returns a pointer to a new Image created from a file.

func NewImageFromHTTPResponse

func NewImageFromHTTPResponse(httpResponse *http.Response) (*Image, error)

Returns a pointer to a new Image created from an HTTP response object.

type ImageDimensions

type ImageDimensions struct {
	Width  uint64
	Height uint64
}

Width and height of an image.

func (ImageDimensions) AspectRatio

func (d ImageDimensions) AspectRatio() float64

Returns the image dimension's aspect ratio.

func (ImageDimensions) String

func (d ImageDimensions) String() string

type ImageProcessor

type ImageProcessor interface {
	ProcessImage(*Image, *ImageProcessorOptions) *Image
}

ImageProcessor is the public interface for the image processor. It exposes a single method to process an image with options.

func NewImageProcessorWithConfig

func NewImageProcessorWithConfig(config *ProcessorConfig) ImageProcessor

Creates a new ImageProcessor instance using configuration settings.

type ImageProcessorOptions

type ImageProcessorOptions struct {
	Dimensions ImageDimensions
	BlurRadius float64
}

ImageProcessorOptions specify the request parameters for the processing operation.

type ImageSource

type ImageSource interface {
	GetImage(*ImageSourceOptions) *Image
}

func NewFileSystemImageSourceWithConfig added in v0.1.1

func NewFileSystemImageSourceWithConfig(config *SourceConfig) ImageSource

func NewImageSourceWithConfig

func NewImageSourceWithConfig(config *SourceConfig) ImageSource

func NewS3ImageSourceWithConfig

func NewS3ImageSourceWithConfig(config *SourceConfig) ImageSource

type ImageSourceFactoryFunction

type ImageSourceFactoryFunction func(*SourceConfig) ImageSource

type ImageSourceOptions

type ImageSourceOptions struct {
	Path string
}

type ImageSourceType

type ImageSourceType string
const (
	IMAGE_SOURCE_TYPE_FILESYSTEM ImageSourceType = "filesystem"
)
const (
	IMAGE_SOURCE_TYPE_S3 ImageSourceType = "s3"
)

type Logger

type Logger struct {
	*log.Logger
	Name string
}

func NewLogger

func NewLogger(nameFormat string, v ...interface{}) *Logger

func (*Logger) Debug

func (l *Logger) Debug(format string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(format string, v ...interface{})

func (*Logger) Info

func (l *Logger) Info(format string, v ...interface{})

func (*Logger) Log

func (l *Logger) Log(level, format string, v ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(format string, v ...interface{})

type ProcessorConfig

type ProcessorConfig struct {
	Name                    string
	ImageCompressionQuality uint64
	MaintainAspectRatio     bool
	DefaultImageHeight      uint64
	DefaultImageWidth       uint64
	MaxImageHeight          uint64
	MaxImageWidth           uint64
	MaxBlurRadiusPercentage float64
}

ProcessorConfig holds the configuration settings for the image processor.

type Route

type Route struct {
	Name           string
	Pattern        *regexp.Regexp
	ImagePathIndex int
	Processor      ImageProcessor
	Source         ImageSource
	Statter        Statter
}

A Route handles the business logic of a Halfshell request. It contains a Processor and a Source. When a request is serviced, the appropriate route is chosen after which the image is retrieved from the source and processed by the processor.

func NewRouteWithConfig

func NewRouteWithConfig(config *RouteConfig) *Route

Returns a pointer to a new Route instance created using the provided configuration settings.

func (*Route) ShouldHandleRequest

func (p *Route) ShouldHandleRequest(r *http.Request) bool

Accepts an HTTP request and returns a bool indicating whether the route should handle the request.

func (*Route) SourceAndProcessorOptionsForRequest

func (p *Route) SourceAndProcessorOptionsForRequest(r *http.Request) (
	*ImageSourceOptions, *ImageProcessorOptions)

Parses the source and processor options from the request.

type RouteConfig

type RouteConfig struct {
	Name            string
	Pattern         *regexp.Regexp
	ImagePathIndex  int
	SourceConfig    *SourceConfig
	ProcessorConfig *ProcessorConfig
}

RouteConfig holds the configuration settings for a particular route.

type S3ImageSource

type S3ImageSource struct {
	Config *SourceConfig
	Logger *Logger
}

func (*S3ImageSource) GetImage

func (s *S3ImageSource) GetImage(request *ImageSourceOptions) *Image

type Server

type Server struct {
	*http.Server
	Routes []*Route
	Logger *Logger
}

func NewServerWithConfigAndRoutes

func NewServerWithConfigAndRoutes(config *ServerConfig, routes []*Route) *Server

func (*Server) ImageRequestHandler

func (s *Server) ImageRequestHandler(w *HalfshellResponseWriter, r *HalfshellRequest)

func (*Server) LogRequest

func (s *Server) LogRequest(w *HalfshellResponseWriter, r *HalfshellRequest)

func (*Server) NewHalfshellRequest

func (s *Server) NewHalfshellRequest(r *http.Request) *HalfshellRequest

func (*Server) NewHalfshellResponseWriter

func (s *Server) NewHalfshellResponseWriter(w http.ResponseWriter) *HalfshellResponseWriter

Create a new HalfshellResponseWriter by wrapping http.ResponseWriter.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerConfig

type ServerConfig struct {
	Port         uint64
	ReadTimeout  uint64
	WriteTimeout uint64
}

ServerConfig holds the configuration settings relevant for the HTTP server.

type SourceConfig

type SourceConfig struct {
	Name        string
	Type        ImageSourceType
	S3AccessKey string
	S3Bucket    string
	S3SecretKey string
	Directory   string
}

SourceConfig holds the type information and configuration settings for a particular image source.

type Statter

type Statter interface {
	RegisterRequest(*HalfshellResponseWriter, *HalfshellRequest)
}

func NewStatterWithConfig

func NewStatterWithConfig(config *RouteConfig) Statter

Jump to

Keyboard shortcuts

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