stream

package
v3.6.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackoffDefault

func BackoffDefault() *backoff.ExponentialBackOff

BackoffDefault is the default Backoff behavior for network call retries.

Previous values from k8s.io/apimachinery/pkg/util/wait.`Backoff`: - Duration: time.Second - Factor: 2 - Jitter: 0.1 - Steps: 45 - Cap: time.Second * 60

Types

type ExternalRequest

type ExternalRequest struct {
	RequestParams  interface{}
	StreamProducer Producer
}

An ExternalRequest is anything that can create and then consume any stream. The request comes bundled with something that can produce a stream (io.Reader), and something that can read from that stream to populate some arbitrary data structure.

type Fake

type Fake struct {
	Bytes []byte
	// contains filtered or unexported fields
}

Fake is a predefined stream (set with Bytes).

func (*Fake) Close

func (producer *Fake) Close() error

Close does nothing, as there is no actual subprocess to close.

func (*Fake) Produce

func (producer *Fake) Produce() (stream, blankStderr io.Reader, err error)

Produce a fake stream on stdout (and an empty stderr). Unlike a real stream, this does not call a subprocess --- instead it just provides a predefined stream (Bytes) to create an io.Reader for stdout. The stderr stream is empty.

type HTTP

type HTTP struct {
	Req *http.Request
	Res *http.Response
}

HTTP is a wrapper around the net/http's Request type.

func (*HTTP) Close

func (h *HTTP) Close() error

Close closes the http request. This is required because otherwise there will be a resource leak. See https://stackoverflow.com/a/33238755/437583

func (*HTTP) Produce

func (h *HTTP) Produce() (stdOut, stdErr io.Reader, err error)

Produce runs the external process and returns two io.Readers (to stdout and stderr). In this case we equate the http.Respose "Body" with stdout.

type Producer

type Producer interface {
	// The first two io.Readers are expected to be the stdout and stderr streams
	// from the process, respectively.
	Produce() (io.Reader, io.Reader, error)
	Close() error
}

Producer is an interface for anything that can generate an io.Reader from which we can read from (typically JSON output).

type Subprocess

type Subprocess struct {
	CmdInvocation []string
	// contains filtered or unexported fields
}

Subprocess can spawn a subprocess and read from it. It can be used to read from an io.Reader that produces JSON, or whatever else.

func (*Subprocess) Close

func (sp *Subprocess) Close() error

Close the subprocess by waiting for it.

func (*Subprocess) Produce

func (sp *Subprocess) Produce() (stdOut, stdErr io.Reader, err error)

Produce runs the external process and returns two io.Readers (to stdout and stderr).

Jump to

Keyboard shortcuts

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