bufferedpipe

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Provides a mechanism for writing data to a buffer and reading it later. The buffer is stored in a map of buffered pipes, which are removed after a certain amount of time. The output of a buffered pipe can be read by sending a GET request to a specific URL.

Index

Constants

View Source
const (
	BufferedPipeMapTTL    = 30 * time.Second     // The time-to-live for a buffered pipe in the map of buffered pipes.
	BufferedPipeGetterUrl = "/api/buffered-pipe" // The URL for getting the output of a buffered pipe.
)

Variables

This section is empty.

Functions

func HandleGetBufferedPipeOutput

func HandleGetBufferedPipeOutput(w http.ResponseWriter, r *http.Request)

Handle a HTTP GET request to get the output of a buffered pipe, given a key.

func SetBufferedPipe

func SetBufferedPipe(pipe *BufferedPipe)

Set a buffered pipe in the map of buffered pipes.

Types

type BufferedPipe

type BufferedPipe struct {
	Key string // a unique key for the pipe
	// contains filtered or unexported fields
}

A pipe that allows for lazy writing to a downstream writer. Data written to the pipe is buffered until WriteTo is called.

func GetBufferedPipe

func GetBufferedPipe(key string) (*BufferedPipe, bool)

Get a buffered pipe from the map of buffered pipes, given a key.

func NewBufferedPipe

func NewBufferedPipe(timeout time.Duration) *BufferedPipe

Create a new BufferedPipe with a timeout. The writer will be closed after the timeout

func (*BufferedPipe) Close

func (pipe *BufferedPipe) Close() error

Close the pipe. This will cause any blocking WriteTo calls to return.

func (*BufferedPipe) GetOutputUrl

func (pipe *BufferedPipe) GetOutputUrl() (string, error)

Get the URL for reading the output of the pipe.

func (*BufferedPipe) Write

func (pipe *BufferedPipe) Write(p []byte) (n int, err error)

Write data to the buffer.

func (*BufferedPipe) WriteTo

func (pipe *BufferedPipe) WriteTo(w io.Writer) (n int64, err error)

Write all buffered data to a waiting writer and block, sending all subsequent data until the pipe is closed. Only one goroutine should call this method.

type BufferedPipeMap

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

Jump to

Keyboard shortcuts

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