httpinstrumented

package
v0.0.0-...-aefccaf Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &Client{http.Client{}, &ClientMetrics{}}

DefaultClient replaces http.DefaultClient

Functions

This section is empty.

Types

type Client

type Client struct {
	http.Client
	Metrics *ClientMetrics
}

Client is an instrumented version of http.client

func (*Client) Do

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

Do behave like http.Client but getting performance metrics

func (*Client) Get

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

Get replaces the http.Client Get

func (*Client) Post

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

Post replaces the http.Client Post

type ClientMetrics

type ClientMetrics struct {
	InitTime    time.Time
	ElapsedTime time.Duration
}

ClientMetrics contains measures at client level

type Request

type Request struct {
	*http.Request
	Metrics *RequestMetrics
}

Request defines a requests with performance metrics

func NewRequest

func NewRequest(method, url string, body io.Reader) (*Request, error)

NewRequest wraps NewRequestWithContext using the background context.

func NewRequestWithContext

func NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*Request, error)

NewRequestWithContext returns an standard http request powered by metrics

type RequestMetrics

type RequestMetrics struct {
	StartTime             time.Time
	DNSTime               time.Duration
	TCPDialTime           time.Duration
	TLSTime               time.Duration
	RequestWriteTime      time.Duration
	FirstResponseByteTime time.Duration
	HostPort              string
}

RequestMetrics defines request measures

type Response

type Response struct {
	http.Response
	Metrics *ResponseMetrics
}

Response adds metrics to http.Request

func Get

func Get(url string) (resp *Response, err error)

Get replaces the http.Get

func Post

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

Post replaces the http.Post

type ResponseMetrics

type ResponseMetrics struct {
	*RequestMetrics
	*ClientMetrics
}

ResponseMetrics includes all metrics taken in previous steps

Jump to

Keyboard shortcuts

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