ohttp

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: ISC Imports: 16 Imported by: 0

Documentation

Overview

Package ohttp is an observable http package. It can be used for building HTTP servers and clients that automatically report logs, metrics, and traces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a drop-in replacement for the standard http.Client. It is an observable http client with logging, metrics, and tracing.

func NewClient

func NewClient(client *http.Client, observer observer.Observer, opts Options) *Client

NewClient creates a new observable http client.

func (*Client) CloseIdleConnections

func (c *Client) CloseIdleConnections()

CloseIdleConnections is the observable counterpart of standard http Client.CloseIdleConnections.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do is the observable counterpart of standard http Client.Do.

func (*Client) Get

func (c *Client) Get(url string) (resp *http.Response, err error)

Get is the observable counterpart of standard http Client.Get. Using this method, request context (UUID and trace) will be auto-generated. If you have a context for the request, consider using the Do method.

func (*Client) Head

func (c *Client) Head(url string) (resp *http.Response, err error)

Head is the observable counterpart of standard http Client.Head. Using this method, request context (UUID and trace) will be auto-generated. If you have a context for the request, consider using the Do method.

func (*Client) Post

func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

Post is the observable counterpart of standard http Client.Post. Using this method, request context (UUID and trace) will be auto-generated. If you have a context for the request, consider using the Do method.

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error)

PostForm is the observable counterpart of standard http Client.PostForm. Using this method, request context (UUID and trace) will be auto-generated. If you have a context for the request, consider using the Do method.

type Middleware

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

Middleware creates observable http handlers with logging, metrics, and tracing.

func NewMiddleware

func NewMiddleware(observer observer.Observer, opts Options) *Middleware

NewMiddleware creates a new http middleware for observability.

func (*Middleware) Wrap

func (m *Middleware) Wrap(next http.HandlerFunc) http.HandlerFunc

Wrap wraps an existing http handler function and returns a new observable handler function. This can be used for making http handlers observable via logging, metrics, tracing, etc. It also observes and recovers panics that happened inside the inner http handler.

type Options

type Options struct {
	IDRegexp *regexp.Regexp
}

Options are optional configurations for middleware and clients.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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