persistent

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(cap int, interval time.Duration, writer Storage) (*Buffer, error)

NewBuffer creates a new buffer with the given capacity

func (*Buffer) Clear

func (b *Buffer) Clear() error

Clear clears the buffer and saved data

func (*Buffer) Close

func (b *Buffer) Close(ctx context.Context) error

Close closes the Buffer. flush the data in the buffer before close

func (*Buffer) Flush

func (b *Buffer) Flush() error

Flush writes the buffer to the persistent storage. Flush method is groutine safe and can be called concurrently.

func (*Buffer) Get

func (b *Buffer) Get() (string, error)

Get returns data from persistent storage

func (*Buffer) Set

func (b *Buffer) Set(s string) error

Set adds a string to the buffer

func (*Buffer) Watch

func (b *Buffer) Watch(ctx context.Context)

Watch starts a loop that flushes the buffer at the given interval

type File

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

func NewFileWriter

func NewFileWriter(filepath string) (*File, error)

func (*File) Clear

func (w *File) Clear() error

func (*File) Close

func (w *File) Close(ctx context.Context) error

func (*File) Read

func (w *File) Read() (string, error)

func (*File) Write

func (w *File) Write(s string) error

type Log

type Log struct{}

Log is a writer that writes to the log.

This is for testing purposes and may be removed and should not be used in a production environment.

func NewLogWriter

func NewLogWriter() *Log

func (*Log) Clear

func (l *Log) Clear() error

func (*Log) Close

func (l *Log) Close(ctx context.Context) error

func (*Log) Read

func (l *Log) Read() (string, error)

func (*Log) Write

func (l *Log) Write(s string) error

type Storage

type Storage interface {
	Write(s string) error
	Clear() error
	Read() (string, error)
	Close(ctx context.Context) error
}

type StorageBuffer

type StorageBuffer interface {
	Watch(ctx context.Context)
	Set(s string) error
	Get() (string, error)
	Flush() error
	Clear() error
	Close(ctx context.Context) error
}

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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