http

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: ISC Imports: 12 Imported by: 0

README

http

This package provides utilities for HTTP servers and clients.

Item Description
http.Error An error type capturing context and information about a failed http request.
http.ResponseWriter An implementation of standard http.ResponseWriter for recording status code.
http.ClientMiddleware A client-side middleware providing wrappers for logging, metrics, tracing, etc.
http.ServerMiddleware A server-side middleware providing wrappers for http handlers for logging, metrics, tracing, etc.

Quick Start

You can see an example of using the middleware here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerForRequest

func LoggerForRequest(r *http.Request) (*log.Logger, bool)

LoggerForRequest returns a logger set by http middleware on each request context

Types

type ClientMiddleware added in v0.2.8

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

ClientMiddleware is an http client middleware for logging, metrics, tracing, etc.

func NewClientMiddleware added in v0.2.8

func NewClientMiddleware(logger *log.Logger, mf *metrics.Factory, tracer opentracing.Tracer) *ClientMiddleware

NewClientMiddleware creates a new instance of http client middleware

func (*ClientMiddleware) Logging added in v0.2.8

func (m *ClientMiddleware) Logging(next Doer) Doer

Logging takes care of logging for outgoing http requests Request id will be read from reqeust context if present

func (*ClientMiddleware) Metrics added in v0.2.8

func (m *ClientMiddleware) Metrics(next Doer) Doer

Metrics takes care of metrics for outgoing http requests

func (*ClientMiddleware) RequestID added in v0.2.8

func (m *ClientMiddleware) RequestID(next Doer) Doer

RequestID ensures outgoing requests have unique ids This middleware ensures the request headers and context have a unique id A new request id will be generated if needed

func (*ClientMiddleware) Tracing added in v0.2.8

func (m *ClientMiddleware) Tracing(next Doer) Doer

Tracing takes care of tracing for outgoing http requests Trace information will be read from reqeust context if present

type Doer

type Doer func(*http.Request) (*http.Response, error)

Doer is the interface for standard http.Client Do method

type Error

type Error struct {
	Request    *http.Request
	StatusCode int
	Message    string
}

Error is an http error

func NewError

func NewError(res *http.Response) *Error

NewError creates a new instance of Error

func (*Error) Error

func (e *Error) Error() string

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	StatusCode  int
	StatusClass string
}

ResponseWriter extends the functionality of standard http.ResponseWriter

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) *ResponseWriter

NewResponseWriter creates a new response writer

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(statusCode int)

WriteHeader overrides the default implementation of http.WriteHeader

type ServerMiddleware added in v0.2.8

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

ServerMiddleware is an http server middleware for logging, metrics, tracing, etc.

func NewServerMiddleware added in v0.2.8

func NewServerMiddleware(logger *log.Logger, mf *metrics.Factory, tracer opentracing.Tracer) *ServerMiddleware

NewServerMiddleware creates a new instance of http server middleware

func (*ServerMiddleware) Logging added in v0.2.8

Logging takes care of logging for incoming http requests Request id will be read from reqeust headers if present

func (*ServerMiddleware) Metrics added in v0.2.8

Metrics takes care of metrics for incoming http requests

func (*ServerMiddleware) RequestID added in v0.2.8

func (m *ServerMiddleware) RequestID(next http.HandlerFunc) http.HandlerFunc

RequestID ensures incoming requests have unique ids This middleware ensures the request headers and context have a unique id A new request id will be generated if needed

func (*ServerMiddleware) Tracing added in v0.2.8

Tracing takes care of tracing for incoming http requests Trace information will be read from reqeust headers if present

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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