Documentation
¶
Index ¶
- Constants
- func RegisterSource(sourceType ImageSourceType, factory ImageSourceFactoryFunction)
- type Config
- type Halfshell
- type HalfshellRequest
- type HalfshellResponseWriter
- func (hw *HalfshellResponseWriter) SetHeader(name, value string)
- func (hw *HalfshellResponseWriter) Write(data []byte) (int, error)
- func (hw *HalfshellResponseWriter) WriteError(message string, status int)
- func (hw *HalfshellResponseWriter) WriteHeader(status int)
- func (hw *HalfshellResponseWriter) WriteImage(image *Image)
- type Image
- type ImageDimensions
- type ImageProcessor
- type ImageProcessorOptions
- type ImageSource
- type ImageSourceFactoryFunction
- type ImageSourceOptions
- type ImageSourceType
- type Logger
- type ProcessorConfig
- type Route
- type RouteConfig
- type S3ImageSource
- type Server
- func (s *Server) ImageRequestHandler(w *HalfshellResponseWriter, r *HalfshellRequest)
- func (s *Server) LogRequest(w *HalfshellResponseWriter, r *HalfshellRequest)
- func (s *Server) NewHalfshellRequest(r *http.Request) *HalfshellRequest
- func (s *Server) NewHalfshellResponseWriter(w http.ResponseWriter) *HalfshellResponseWriter
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type ServerConfig
- type SourceConfig
- type Statter
Constants ¶
const STARTUP_TEMPLATE_STRING = `` /* 505-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
RouteConfigs []*RouteConfig
}
Config is the primary configuration of Halfshell. It contains the server configuration as well as a list of route configurations.
func NewConfigFromFile ¶
Parses a JSON configuration file and returns a pointer to a new Config object.
type Halfshell ¶
Halfshell is the primary struct of the program. It holds onto the configuration, the HTTP server, and all the routes.
func NewWithConfig ¶
Create a new Halfshell instance from an instance of Config.
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 ¶
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.
type ImageDimensions ¶
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 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_S3 ImageSourceType = "s3"
)
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 ¶
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 ¶
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.
type ServerConfig ¶
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
}
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