ring

package
v3.10.88 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ring provides a simple ring buffer for storing local data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer is ring buffer

func New

func New(i int) *Buffer

New returns a new buffer of the given size

func (*Buffer) Get

func (b *Buffer) Get(n int) []*Entry

Get returns the last n entries

func (*Buffer) Put

func (b *Buffer) Put(v interface{})

Put adds a new value to ring buffer

func (*Buffer) Since

func (b *Buffer) Since(t time.Time) []*Entry

Since returns the entries since a specific time

func (*Buffer) Size

func (b *Buffer) Size() int

Size returns the size of the ring buffer

func (*Buffer) Stream

func (b *Buffer) Stream() (<-chan *Entry, chan bool)

Stream logs from the buffer Close the channel when you want to stop

type Entry

type Entry struct {
	Timestamp time.Time
	Value     interface{}
}

Entry is ring buffer data entry

type Stream

type Stream struct {
	// Buffered entries
	Entries chan *Entry
	// Stop channel
	Stop chan bool
	// ID of the stream
	ID string
}

Stream is used to stream the buffer

Jump to

Keyboard shortcuts

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