http

package
v0.0.0-...-3202c8d Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemeHttp  = Scheme("http://")
	SchemeHttps = Scheme("https://")
)

Variables

This section is empty.

Functions

func EmptyJsonResponse

func EmptyJsonResponse(w http.ResponseWriter, respCode int)

Write an empty JSON Response to w. RespCode is provided as the response code.

Types

type Client

type Client interface {
	// Execute req and return the response. An optional error is returned if execution of the request failed for whatever reason.
	// Note that a non 200 status code will NOT NECESSARILY return an error.
	Do(req *http.Request) (*http.Response, error)
}

Client is an interface used for issuing HTTP requests. It allows for a modular http client making testing easier. Due to the way Go interfaces are resolved, A net/http.Client satisfies this interface. This interface should be used anywhere an http client is needed to facilitate flexibility and ease of testing.

type Config

type Config struct {
	Host string
	Port int
	Tls  struct {
		Enabled bool
		Cert    string
		Key     string
	}
}

type DirectedClient

type DirectedClient struct {
	Client
	Director
}

DirectedClient is a wrapper around a client and a director for convenience.

func (*DirectedClient) IssueRequest

func (c *DirectedClient) IssueRequest(method, resource string, body []byte) (*http.Response, error)

IssueRequest directs a request and executes it, returning the response object and an optional error if something went wrong.

type Director

type Director interface {
	Direct(method, resource string, body []byte) (*http.Request, error)
}

func RoundRobin

func RoundRobin(hosts []string, scheme Scheme) Director

type LoggedHandler

type LoggedHandler struct {
	Handler http.Handler
}

A loggedHandler is an http.Handler implementation that logs the request using the current logger before servicing the request.

After servicing the request, the response is logged using the same logger, before the response is ultimately sent to the downstream client.

func (LoggedHandler) ServeHTTP

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

type Scheme

type Scheme string

type Server

type Server interface {
	Serve() error
	Addr() string
}

func StandardServer

func StandardServer(config Config, handler http.Handler) Server

StandardServer creates a new standardServer instance for serving HTTP requests using the stdlib's http package.

Jump to

Keyboard shortcuts

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