http

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: ISC Imports: 12 Imported by: 0

README

http

This package provides utilities for HTTP servers.

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.ObservabilityMiddleware A middleware providing wrappers for http handlers for logging, metrics, and tracing.

Quick Start

You can see an example of using the observability 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 ClientObservabilityMiddleware

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

ClientObservabilityMiddleware is an http client middleware for logging, metrics, and tracing

func NewClientObservabilityMiddleware

func NewClientObservabilityMiddleware(logger *log.Logger, mf *metrics.Factory, tracer opentracing.Tracer) *ClientObservabilityMiddleware

NewClientObservabilityMiddleware creates a new instance of http client middleware for observability

func (*ClientObservabilityMiddleware) Wrap

Wrap takes care of logging, metrics, and tracing for client-side http requests

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 ServerObservabilityMiddleware

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

ServerObservabilityMiddleware is an http server middleware for logging, metrics, and tracing

func NewServerObservabilityMiddleware

func NewServerObservabilityMiddleware(logger *log.Logger, mf *metrics.Factory, tracer opentracing.Tracer) *ServerObservabilityMiddleware

NewServerObservabilityMiddleware creates a new instance of http server middleware for observability

func (*ServerObservabilityMiddleware) Wrap

Wrap accepts an http handler and return a new http handler that takes care of logging, metrics, and tracing

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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