Documentation ¶
Index ¶
- Constants
- func RegisterSource(sourceType ImageSourceType, factory ImageSourceFactoryFunction)
- type Config
- type FileSystemImageSource
- type HttpImageSource
- type Image
- type ImageProcessorOptions
- type ImageSource
- func NewFileSystemImageSourceWithConfig(config *SourceConfig) (ImageSource, error)
- func NewHttpImageSourceWithConfig(config *SourceConfig) (ImageSource, error)
- func NewImageSourceWithConfig(config *SourceConfig) (ImageSource, error)
- func NewS3ImageSourceWithConfig(config *SourceConfig) (ImageSource, error)
- type ImageSourceFactoryFunction
- type ImageSourceOptions
- type ImageSourceType
- type Nibbleshell
- type Request
- type ResponseWriter
- type Route
- type RouteConfig
- type S3ImageSource
- type Server
- func (s *Server) ImageRequestHandler(w *ResponseWriter, r *Request)
- func (s *Server) LogRequest(w *ResponseWriter, r *Request)
- func (s *Server) NewRequest(r *http.Request) (*Request, error)
- func (s *Server) NewResponseWriter(w http.ResponseWriter) *ResponseWriter
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type ServerConfig
- type SourceConfig
- type Statter
- type StatterConfig
Constants ¶
const ( JPEG imageFormat = "jpeg" PNG imageFormat = "png" )
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 ¶
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)
type ImageProcessorOptions ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) NewResponseWriter ¶
func (s *Server) NewResponseWriter(w http.ResponseWriter) *ResponseWriter
NewResponseWriter creates a new ResponseWriter 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 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 ¶
StatterConfig holds configuration data for StatsD