changelog

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changelog

type Changelog[T comparable] struct {
	// contains filtered or unexported fields
}

Changelog manages a list of changes (entries) for a single type. When instantiating a Changelog struct, one must supply the maximum amount of changes that can be tracked.

ATTENTION: You should use Changelog within a struct and provide methods to access it, coordinating access through your struct mutexes. DO NOT EXPOSE the Changelog object directly to the outside world as it is not thread-safe.

func NewChangelog

func NewChangelog[T comparable](maxEntries MaxEntries) *Changelog[T]

NewChangelog initializes a new `Changelog` with the specified maximum number of entries.

func (*Changelog[T]) Count added in v0.23.0

func (c *Changelog[T]) Count() int

Count returns the number of entries recorded.

func (*Changelog[T]) Get

func (c *Changelog[T]) Get(timestamp time.Time) T

Get retrieves the value of the entry at or before the given timestamp. If no matching entry is found, it returns the default value for the entry type.

func (*Changelog[T]) GetAll

func (c *Changelog[T]) GetAll() []T

GetAll retrieves all values, from the newest to the oldest.

func (*Changelog[T]) GetCurrent

func (c *Changelog[T]) GetCurrent() T

GetCurrent retrieves the most recent value. If no entry is found, it returns the default value for the entry type.

func (*Changelog[T]) Set

func (c *Changelog[T]) Set(value T, timestamp time.Time)

Set adds or updates an entry in the Changelog, ordered by timestamp. If the new entry has the same value as the latest one, only the timestamp is updated. If there are already the maximum number of entries, it reuses or replaces an existing entry.

type MaxEntries added in v0.23.0

type MaxEntries uint8

MaxEntries represents the maximum number of changes that can be tracked.

Jump to

Keyboard shortcuts

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