pipeline

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pipeline

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

Pipeline represents a primitive for sending HTTP requests and receiving responses. Its behavior can be extended by specifying policies during construction.

func NewPipeline

func NewPipeline(transport Transporter, policies ...Policy) Pipeline

NewPipeline creates a new Pipeline object from the specified Policies.

func (Pipeline) Do

func (p Pipeline) Do(req *Request) (*http.Response, error)

Do is called for each and every HTTP request. It passes the request through all the Policy objects (which can transform the Request's URL/query parameters/headers) and ultimately sends the transformed HTTP request over the network.

type Policy

type Policy interface {
	// Do applies the policy to the specified Request.  When implementing a Policy, mutate the
	// request before calling req.Next() to move on to the next policy, and respond to the result
	// before returning to the caller.
	Do(req *Request) (*http.Response, error)
}

Policy represents an extensibility point for the Pipeline that can mutate the specified Request and react to the received Response.

type PolicyFunc

type PolicyFunc func(*Request) (*http.Response, error)

PolicyFunc is a type that implements the Policy interface. Use this type when implementing a stateless policy as a first-class function.

func (PolicyFunc) Do

func (pf PolicyFunc) Do(req *Request) (*http.Response, error)

Do implements the Policy interface on PolicyFunc.

type Request

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

Request is an abstraction over the creation of an HTTP request as it passes through the pipeline. Don't use this type directly, use NewRequest() instead.

func NewRequest

func NewRequest(ctx context.Context, httpMethod string, endpoint string) (*Request, error)

NewRequest creates a new Request with the specified input.

func (*Request) Body

func (req *Request) Body() io.ReadSeekCloser

Body returns the original body specified when the Request was created.

func (*Request) Clone

func (req *Request) Clone(ctx context.Context) *Request

Clone returns a deep copy of the request with its context changed to ctx.

func (*Request) Close

func (req *Request) Close() error

Close closes the request body.

func (*Request) Next

func (req *Request) Next() (*http.Response, error)

Next calls the next policy in the pipeline. If there are no more policies, nil and an error are returned. This method is intended to be called from pipeline policies. To send a request through a pipeline call Pipeline.Do().

func (*Request) OperationValue

func (req *Request) OperationValue(value interface{}) bool

OperationValue looks for a value set by SetOperationValue().

func (*Request) Raw

func (req *Request) Raw() *http.Request

Raw returns the underlying HTTP request.

func (*Request) RewindBody

func (req *Request) RewindBody() error

RewindBody seeks the request's Body stream back to the beginning so it can be resent when retrying an operation.

func (*Request) SetBody

func (req *Request) SetBody(body io.ReadSeekCloser, contentType string) error

SetBody sets the specified ReadSeekCloser as the HTTP request body.

func (*Request) SetOperationValue

func (req *Request) SetOperationValue(value interface{})

SetOperationValue adds/changes a mutable key/value associated with a single operation.

func (*Request) SkipBodyDownload

func (req *Request) SkipBodyDownload()

SkipBodyDownload will disable automatic downloading of the response body.

type Transporter

type Transporter interface {
	// Do sends the HTTP request and returns the HTTP response or error.
	Do(req *http.Request) (*http.Response, error)
}

Transporter represents an HTTP pipeline transport used to send HTTP requests and receive responses.

Jump to

Keyboard shortcuts

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