storage

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: MPL-2.0 Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileReader

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

FileReader is the common code to read the storages until the subscription channel is closed

func (*FileReader) Close

func (r *FileReader) Close() error

Close closes the underlying storage

func (*FileReader) Read

func (r *FileReader) Read(p []byte) (n int, err error)

type FileStorage

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

FileStorage saves the content into a file

func (*FileStorage) Clean

func (f *FileStorage) Clean() error

Clean removes the file

func (*FileStorage) Close

func (f *FileStorage) Close() error

Close the underlying file

func (*FileStorage) Flush

func (f *FileStorage) Flush() error

Flush syncs the underlying file

func (*FileStorage) GetReader

func (f *FileStorage) GetReader() (io.ReadCloser, error)

GetReader returns a new file descriptor to the same file

func (*FileStorage) Write

func (f *FileStorage) Write(p []byte) (n int, err error)

type NoStorage

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

NoStorage writes the content directly into the ResponseWriter TODO remove this

func (*NoStorage) Clean

func (b *NoStorage) Clean() error

Clean does nothing in the buffer it will be garbage collected eventually

func (*NoStorage) Close

func (b *NoStorage) Close() error

Close the storage entry

func (*NoStorage) Flush

func (b *NoStorage) Flush() error

Flush does nothing in a buffer

func (*NoStorage) GetReader

func (b *NoStorage) GetReader() (io.ReadCloser, error)

GetReader returns the same buffer

func (*NoStorage) Write

func (b *NoStorage) Write(p []byte) (n int, err error)

type ResponseStorage

type ResponseStorage interface {
	io.Writer
	io.Closer
	Clean() error
	Flush() error
	GetReader() (io.ReadCloser, error)
}

ResponseStorage represents a possible storage for the entry

func NewFileStorage

func NewFileStorage(path string) (ResponseStorage, error)

NewFileStorage creates a new temp file that will be used as a the storage of the cache entry

func WrapResponseWriter

func WrapResponseWriter(w http.ResponseWriter) ResponseStorage

WrapResponseWriter wraps an http.ResponseWriter and gives it the ResponseStorage interface

type Subscription

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

Subscription is a structure to sync all File Readers in a pub/sub style. It's useful when there are many readers that want to read from a single writter. The writter can create a subscription and give each other a NewSubscriber(). Each time the producer call NotifyAll the clients will get a channel with the value. In case a client blocks it will miss the next reads that will not be queued.

func NewSubscription

func NewSubscription() *Subscription

func (*Subscription) Close

func (s *Subscription) Close()

func (*Subscription) NewSubscriber

func (s *Subscription) NewSubscriber() <-chan int

func (*Subscription) NotifyAll

func (s *Subscription) NotifyAll(newBytes int)

func (*Subscription) RemoveSubscriber

func (s *Subscription) RemoveSubscriber(subscriber <-chan int)

func (*Subscription) WaitAll

func (s *Subscription) WaitAll()

WaitAll waits until are subscribers ends

Jump to

Keyboard shortcuts

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