imgserver

package module
v0.0.0-...-a231fe7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2016 License: Apache-2.0 Imports: 21 Imported by: 1

README

Build Status GoDoc

imgserver

Test task for Yandex internship. Simple Go server that download all <img> tag images from HTML page, and return page with all images encoded base64. URL of HTTP page passes by query attribute. Support many different page encodings

usage

go get github.com/Skipor/imgserver/cmd/imgserver

$GOBIN/imgserver -p 8888

curl http://localhost:8888/?url=https://habrahabr.ru/interesting/

Documentation

Overview

Test task for Yandex internship. Simple Go server that download all <img> tag images from HTML page, and return page with all images encoded base64. URL of HTTP page passes by query attribute. Support many different page encodings

Index

Constants

View Source
const (
	CtxHTTPClientKey = "httpclient"
	CtxLoggerKey     = "logger"
)

public keys upper handler can

View Source
const (
	//logger field to indicate log msg emitter
	FromLoggerFieldKey = "from"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextAdaptor

type ContextAdaptor struct {
	Handler
	Ctx context.Context
}

Implement http.Handler interface for imgserver.Handler

func NewImgCtxAdaptor

func NewImgCtxAdaptor(log Logger, client *http.Client, timeout time.Duration) ContextAdaptor

func (ContextAdaptor) ServeHTTP

func (h ContextAdaptor) ServeHTTP(w http.ResponseWriter, req *http.Request)

type ErrorHandler

type ErrorHandler interface {
	HandleError(ctx context.Context, req *http.Request, err error) *Response
}

type ErrorLogger

type ErrorLogger struct {
}

func (ErrorLogger) HandleError

func (h ErrorLogger) HandleError(ctx context.Context, req *http.Request, err error) *Response

type Handler

type Handler interface {
	ServeHTTPC(context.Context, http.ResponseWriter, *http.Request)
}

type HandlerError

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

func NewHandlerError

func NewHandlerError(statusCode int, description string) *HandlerError

func (*HandlerError) Error

func (e *HandlerError) Error() string

type ImgHandler

type ImgHandler struct {
	Log          Logger
	LogicHandler LogicHandler
	ErrorHandler ErrorHandler
	Timeout      time.Duration //no timeout if 0
	// contains filtered or unexported fields
}

func (*ImgHandler) ServeHTTPC

func (h *ImgHandler) ServeHTTPC(ctx context.Context, w http.ResponseWriter, req *http.Request)

type ImgLogicHandler

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

func NewImgLogicHandler

func NewImgLogicHandler(client *http.Client) *ImgLogicHandler

func (*ImgLogicHandler) HandleLogic

func (h *ImgLogicHandler) HandleLogic(ctx context.Context, req *http.Request) (*Response, error)

type Logger

type Logger interface {
	logrus.FieldLogger
}

func SetEmitter

func SetEmitter(log Logger, emitter string) Logger

type LogicHandler

type LogicHandler interface {
	HandleLogic(ctx context.Context, req *http.Request) (*Response, error)
}

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	Body       *bytes.Buffer
}

func NewInternalErrorResponse

func NewInternalErrorResponse() *Response

func NewResponse

func NewResponse() *Response

func NewTimeoutResponse

func NewTimeoutResponse() *Response

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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