Back to

Package httputil

Latest Go to latest

The latest major version is v2.

Published: Dec 6, 2019 | License: CC-BY-4.0 | Module:


func ErrorHandler

func ErrorHandler(log *logrus.Entry) echo.HTTPErrorHandler

ErrorHandler creates an echo.HTTPErrorHandler that handles errors by sending JSON responses containing error details.

It will attempt to extract additional error context using cockroachdb/errors.

func InfoHTTPHandler

func InfoHTTPHandler(name, version string) http.HandlerFunc

InfoHTTPHandler creates an http.HandlerFunc that handles requests for server information.

func InfoHandler

func InfoHandler(name, version string) echo.HandlerFunc

InfoHandler creates an echo.HandlerFunc that handles requests for server information.

func JSONPretty

func JSONPretty(c echo.Context, v zero.Interface) error

JSONPretty sends v as JSON, but with pretty spacing.

type BasicClient

type BasicClient interface {
	Do(req *http.Request) (*http.Response, error)

A BasicClient can perform HTTP requests.

type BasicClientOption

type BasicClientOption func(*BasicClientOptions)

A BasicClientOption modifies a BasicClientOptions.

func BasicWithHTTPClient

func BasicWithHTTPClient(c *http.Client) BasicClientOption

BasicWithHTTPClient configures a BasicClient to make HTTP requests using c.

type BasicClientOptions

type BasicClientOptions struct {
	HTTPClient *http.Client

A BasicClientOptions configures a BasicClient.

type CachingTripper

type CachingTripper struct {
	Tripper http.RoundTripper
	// contains filtered or unexported fields

A CachingTripper is an http.RoundTripper that caches http.Responses based on their request URL.

func NewCachingTripper

func NewCachingTripper(
	underlying http.RoundTripper,
	opts ...CachingTripperOption,
) (*CachingTripper, error)

NewCachingTripper creates a new CachingTripper that caches http.Responses from the underlying http.RoundTripper using an LRU cache.

If no underlying http.RoundTripper is provided, http.DefaultTransport will be used.

func (*CachingTripper) Clear

func (ct *CachingTripper) Clear()

Clear clears the CachingTransport's cache.

func (*CachingTripper) RoundTrip

func (ct *CachingTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper for a CachingTripper.

type CachingTripperOption

type CachingTripperOption func(*CachingTripperOptions)

A CachingTripperOption modifies a CachingTripperOptions.

func CachingTripperWithLogger

func CachingTripperWithLogger(log *logrus.Entry) CachingTripperOption

CachingTripperWithLogger configures a CachingTripper to write logs with log.

func CachingTripperWithMaxAge

func CachingTripperWithMaxAge(age time.Duration) CachingTripperOption

CachingTripperWithMaxAge configures a CachingTripper to expire each response after age (the amount of time since the response was received).

type CachingTripperOptions

type CachingTripperOptions struct {
	Logger      *logrus.Entry
	ExpiresFunc ExpiresFunc
	Ristretto   ristretto.Config

A CachingTripperOptions configures a CachingTripper.

type Client

type Client interface {
	Get(url string) (*http.Response, error)

A Client is like a BasicClient, except it contains tasty shortcuts for GET requests.

func ClientFromBasic

func ClientFromBasic(bc BasicClient) Client

ClientFromBasic creates a Client from a BasicClient.

type ExpiresFunc

type ExpiresFunc func(req *http.Request, timestamp time.Time) (expires *time.Time)

ExpiresFunc determines the time at which the cached response for a request must expire.

If the returned value is nil, the response will not expire, and will be cleared by the LRU cache once it reaches its maximum cost.

Similarly, if ExpiresFunc is nil, no time-based expiry will be enforced for any cached responeses.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier