http

package
v0.0.0-...-a1dd794 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package http provides HTTP client and server implementations.

Package http provides HTTP client and server implementations.

Package http provides HTTP client and server implementations.

Package http provides HTTP client and server implementations.

Index

Constants

View Source
const (
	MethodGet     = http.MethodGet
	MethodHead    = http.MethodHead
	MethodPost    = http.MethodPost
	MethodPut     = http.MethodPut
	MethodPatch   = http.MethodPatch
	MethodDelete  = http.MethodDelete
	MethodConnect = http.MethodConnect
	MethodOptions = http.MethodOptions
	MethodTrace   = http.MethodTrace
)

Common HTTP methods.

Variables

View Source
var DefaultClient = mustClient(NewClient(http.DefaultClient))

DefaultClient is the default Client and is used by Get, Head, and Post.

View Source
var DefaultTransport = http.DefaultTransport

DefaultTransport is the default implementation of Transport and is used by DefaultClient.

Functions

func GetWithContext

func GetWithContext(ctx context.Context, url string) (resp *http.Response, err error)

GetWithContext is a convenient replacement for http.Get that adds a span around the request.

Types

type Client

type Client = http.Client

A Client is an HTTP client. Its zero value (DefaultClient) is a usable client that uses DefaultTransport.

func NewClient

func NewClient(c *Client, opts ...Option) (*Client, error)

NewClient returns a client that provides OpenTelemetry tracing and metrics.

type Handler

type Handler = http.Handler

A Handler responds to an HTTP request.

type HandlerFunc

type HandlerFunc = http.HandlerFunc

The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

type Option

type Option interface {
	Apply(*config)
}

Option applies a configuration to the given config.

func WithMeterProvider

func WithMeterProvider(mp metric.MeterProvider) Option

WithMeterProvider specifies a meter provider to use for creating a meter. If none is specified, the global provider is used.

func WithOperationName

func WithOperationName(name string) Option

WithOperationName specifies a operation name. If none is specified, the default operation name is used

func WithPropagators

func WithPropagators(ps propagation.TextMapPropagator) Option

WithPropagators specifies a propagators. If none is specified, the global propagator is used.

func WithSpanNameFormatter

func WithSpanNameFormatter(f SpanNameFormatter) Option

WithSpanNameFormatter specifies a formatter to used to format span names. If none is specified, the default SpanNameFormatter is used

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

type OptionFunc

type OptionFunc func(c *config)

OptionFunc provides a convenience wrapper for simple Options that can be represented as functions.

func (OptionFunc) Apply

func (o OptionFunc) Apply(c *config)

Apply will apply the option to the config.

type Request

type Request = http.Request

A Request represents an HTTP request received by a server or to be sent by a client.

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 a new Request given a method, URL, and optional body.

type Response

type Response = http.Response

Response represents the response from an HTTP request.

func Get

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

Get issues a GET to the specified URL.

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

Head issues a HEAD to the specified URL.

func HeadWithContext

func HeadWithContext(ctx context.Context, url string) (resp *Response, err error)

HeadWithContext is a convenient replacement for http.Head that adds a span around the request.

func Post

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

Post issues a POST to the specified URL.

func PostForm

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

PostForm issues a POST to the specified URL, with data's keys and values URL-encoded as the request body.

func PostFormWithContext

func PostFormWithContext(ctx context.Context, url string, data url.Values) (resp *Response, err error)

PostFormWithContext is a convenient replacement for http.PostForm that adds a span around the request.

func PostWithContext

func PostWithContext(ctx context.Context, url, contentType string, body io.Reader) (resp *Response, err error)

PostWithContext is a convenient replacement for http.Post that adds a span around the request.

type RoundTripper

type RoundTripper = http.RoundTripper

RoundTripper is an interface representing the ability to execute a single HTTP transaction, obtaining the Response for a given Request.

func NewOTelTransport

func NewOTelTransport(rt RoundTripper, opts ...Option) (RoundTripper, error)

NewOTelTransport wraps the provided RoundTripper with one that starts a span and injects the span context into the outbound request headers. If none is specified, the DefaultTransport is used.

type SpanNameFormatter

type SpanNameFormatter func(operation string, req *Request) string

SpanNameFormatter creates a custom span name from the operation and db object.

type Transport

type Transport = http.Transport

Transport is an implementation of RoundTripper that supports HTTP, HTTPS, and HTTP proxies.

Jump to

Keyboard shortcuts

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