httpclient

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 7 Imported by: 1

README

httpclient

Wrappers for HTTP client operations

  • Logging requests via a pluggable logger

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTextual

func IsTextual(contentType string) bool

IsTextual tests a media type (a.k.a. content type) to determine whether it describes text or binary content.

Types

type HttpClient

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

HttpClient indicates the core function in http.Client, allowing features to be nested easily.

func NewLoggingClient

func NewLoggingClient(upstream HttpClient, logger Logger, level Level) HttpClient

NewLoggingClient wraps an upstream client and logs all requests made to it.

type Level

type Level int

Level allows control of the level of detail in log messages.

const (
	// Off turns logging off.
	Off Level = iota

	// Discrete log messages contain only a summary of the request and response.
	// No query parameters are printed in order to hide potential personal information.
	Discrete

	// Summary log messages contain only a summary of the request and response,
	// including the full target URL.
	Summary

	// WithHeaders log messages contain a summary and the request/response headers
	WithHeaders

	// WithHeadersAndBodies log messages contain a summary and the request/response headers and bodies
	WithHeadersAndBodies
)

type LogContent

type LogContent struct {
	Header http.Header
	Body   []byte
}

type LogItem

type LogItem struct {
	Method     string
	URL        string
	StatusCode int
	Request    LogContent
	Response   LogContent
	Err        error
	Duration   time.Duration
	Level      Level
}

type Logger

type Logger func(item *LogItem)

func LogWriter

func LogWriter(out io.Writer) Logger

LogWriter returns a new Logger.

type LoggingClient

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

LoggingClient is a HttpClient with a pluggable logger.

func (*LoggingClient) Do

func (l *LoggingClient) Do(req *http.Request) (*http.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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