nibbleshell

package
v0.0.0-...-83953c2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2016 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JPEG imageFormat = "jpeg"
	PNG  imageFormat = "png"
)
View Source
const StartupTemplateString = `` /* 696-byte string literal not displayed */

Variables

This section is empty.

Functions

func RegisterSource

func RegisterSource(sourceType ImageSourceType, factory ImageSourceFactoryFunction)

Types

type Config

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

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

func NewConfigFromFile

func NewConfigFromFile(filepath string) *Config

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

type FileSystemImageSource

type FileSystemImageSource struct {
	Config *SourceConfig
}

func (*FileSystemImageSource) GetImage

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

type HttpImageSource

type HttpImageSource struct {
	Config *SourceConfig
}

func (*HttpImageSource) GetImage

func (s *HttpImageSource) GetImage(request *ImageSourceOptions) (*Image, error)

type Image

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

func NewImageFromBuffer

func NewImageFromBuffer(i io.ReadCloser) (*Image, error)

func NewImageFromFile

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

func (*Image) Bytes

func (i *Image) Bytes() []byte

func (*Image) Height

func (i *Image) Height() uint32

func (*Image) MIMEType

func (i *Image) MIMEType() string

func (*Image) Size

func (i *Image) Size() int

func (*Image) Width

func (i *Image) Width() uint32

type ImageProcessorOptions

type ImageProcessorOptions struct {
	Width, Height, X, Y uint32
	ScaleX, ScaleY      int32
	Quality             uint8
}

func (*ImageProcessorOptions) ProcessImage

func (ipo *ImageProcessorOptions) ProcessImage(source *Image) (*Image, error)

func (*ImageProcessorOptions) String

func (ipo *ImageProcessorOptions) String() string

type ImageSource

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

func NewFileSystemImageSourceWithConfig

func NewFileSystemImageSourceWithConfig(config *SourceConfig) (ImageSource, error)

func NewHttpImageSourceWithConfig

func NewHttpImageSourceWithConfig(config *SourceConfig) (ImageSource, error)

func NewImageSourceWithConfig

func NewImageSourceWithConfig(config *SourceConfig) (ImageSource, error)

func NewS3ImageSourceWithConfig

func NewS3ImageSourceWithConfig(config *SourceConfig) (ImageSource, error)

type ImageSourceFactoryFunction

type ImageSourceFactoryFunction func(*SourceConfig) (ImageSource, error)

type ImageSourceOptions

type ImageSourceOptions struct {
	Path string
}

type ImageSourceType

type ImageSourceType string
const (
	ImageSourceTypeFilesystem ImageSourceType = "filesystem"
)
const (
	ImageSourceTypeHttp ImageSourceType = "http"
)
const (
	ImageSourceTypeS3 ImageSourceType = "s3"
)

type Nibbleshell

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

Nibbleshell 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) (*Nibbleshell, error)

NewWithConfig creates a new instance from an instance of Config.

func (*Nibbleshell) Run

func (h *Nibbleshell) Run() error

Run starts the HTTP server of the service.

type Request

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

type ResponseWriter

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

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

func (*ResponseWriter) SetHeader

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

SetHeader sets the value for a response header.

func (*ResponseWriter) Write

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

Writes data the output stream.

func (*ResponseWriter) WriteError

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

WriteError writes an error response.

func (*ResponseWriter) WriteHeader

func (hw *ResponseWriter) WriteHeader(status int)

WriteHeader forwards to http.ResponseWriter's WriteHeader method.

func (*ResponseWriter) WriteImage

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

WriteImage writes an image to the output stream and sets the appropriate headers.

type Route

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

A Route handles the internal logic of a Halfshell request. 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, statterConfig *StatterConfig) (*Route, error)

NewRouteWithConfig 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

ShouldHandleRequest 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, error)

SourceAndProcessorOptionsForRequest parses the source and processor options from the request.

type RouteConfig

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

RouteConfig holds the configuration settings for a particular route.

type S3ImageSource

type S3ImageSource struct {
	Config *SourceConfig
}

func (*S3ImageSource) GetImage

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

type Server

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

func NewServerWithConfigAndRoutes

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

func (*Server) ImageRequestHandler

func (s *Server) ImageRequestHandler(w *ResponseWriter, r *Request)

func (*Server) LogRequest

func (s *Server) LogRequest(w *ResponseWriter, r *Request)

func (*Server) NewRequest

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

func (*Server) NewResponseWriter

func (s *Server) NewResponseWriter(w http.ResponseWriter) *ResponseWriter

NewResponseWriter creates a new ResponseWriter 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
	Host        string
}

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

type Statter

type Statter interface {
	RegisterRequest(*ResponseWriter, *Request)
}

func NewStatterWithConfig

func NewStatterWithConfig(routeConfig *RouteConfig, statterConfig *StatterConfig) (Statter, error)

type StatterConfig

type StatterConfig struct {
	Host    string
	Port    uint64
	Enabled bool
}

StatterConfig holds configuration data for StatsD

Jump to

Keyboard shortcuts

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