// ServeHTTP is called whenever there is a new request. // This is quite similar to JavaEE Servlet interface. func (h *MyHandler) ServeHTTP(ctx *fasthttp.RequestCtx) { // In the future we can use requester can detect request spammers! // requester := ctx.RemoteAddr() // Increase request count count := &(h.requests) atomic.AddUint64(count, 1) if ctx.IsGet() { url := ctx.URI() operations, format, err, invalid := ParseURI(url, h.imageSource, h.watermarker) if err != nil { ctx.NotFound() logging.Debug(err) return } if invalid != nil { ctx.Error(invalid.Error(), 400) return } blob, err := h.operator.GetBlob(operations...) if err != nil { ctx.NotFound() logging.Debug(err) } else { ctx.SetContentType("image/" + format) ctx.Write(blob) logging.Debug("Blob returned") } } else if ctx.IsPost() { // POST is currently unused so we can use this for testing h.RetrieveHello(ctx) logging.Debug("Post request received") } }