Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyStarted is returned when method `Start` is called on an already started `HTTPServer`. ErrAlreadyStarted = errors.New(`already started`) // ErrNotStarted is returned when method `Stop` is called on a non-started-yet `HTTPServer`. ErrNotStarted = errors.New(`not started`) // ErrImageProcessorIsRequireed is returned when NewHTTPServer is called with nil `proc`. ErrImageProcessorIsRequireed = errors.New(`image processor is required`) )
Functions ¶
This section is empty.
Types ¶
type ErrBadGateway ¶
type ErrBadGateway struct {
Message string
}
ErrBadGateway is an error which will be returned to a browser with as a "Bad Gateway" error
func (*ErrBadGateway) Error ¶
func (err *ErrBadGateway) Error() string
Error just implements interface `error`.
type ErrBadRequest ¶
type ErrBadRequest struct {
Message string
}
ErrBadRequest is an error which will be returned to a browser with as a "Bad Request" error
func (*ErrBadRequest) Error ¶
func (err *ErrBadRequest) Error() string
Error just implements interface `error`.
type ErrForbidden ¶
type ErrForbidden struct {
Message string
}
ErrForbidden is an error which will be returned to a browser with as a "Forbidden" error
func (*ErrForbidden) Error ¶
func (err *ErrForbidden) Error() string
Error just implements interface `error`.
type HTTPServer ¶
type HTTPServer struct { // ImageProcessor is the implementation of image manipulation tool ImageProcessor imageprocessor.ImageProcessor // contains filtered or unexported fields }
HTTPServer is the implemention of an HTTP server which implements `picapi`'s methods
func NewHTTPServer ¶
func NewHTTPServer( proc imageprocessor.ImageProcessor, accessLogger Printfer, handlerLogger Printfer, cacheDuration time.Duration, cacheMaxEntries uint64, cacheMaxEntrySize uint64, ) (srv *HTTPServer, err error)
NewHTTPServer returns a new instance of `HTTPServer`.
`HTTPServer` will not be started automatically. It's required to call method `Start` to start it.
`accessLogger` is used to log requests (similar to an "access.log").
`handlerLogger` is used to log errors and warnings by handlers (similar to "error.log")
func (*HTTPServer) Done ¶
func (srv *HTTPServer) Done() <-chan struct{}
Done returns the `Done()` of the context of the HTTPServer instance.
func (*HTTPServer) Start ¶
func (srv *HTTPServer) Start( ctx context.Context, listenAddress string, ) (err error)
Start creates a listener and starts the process of serving incoming HTTP requests.
func (*HTTPServer) Stop ¶
func (srv *HTTPServer) Stop() (err error)
Stop is anti-Start: it stops the process of serving incoming HTTP requsts and closes the listener.
type Printfer ¶
type Printfer interface { // Printf is a pretty-standart `Printf` (`fmt` is the format and `args` are the arguments for the format). // // For example you can use `log.New` as `Printfer`. Printf(fmt string, args ...interface{}) }
Printfer is a simple logger interface for `NewHTTPServer`