Documentation ¶
Overview ¶
Package acc provides an accumulator mechanism to accumulate, process, and manage data.
Package acc provides an accumulator mechanism to accumulate, process, and manage data.
Package acc provides an accumulator mechanism to accumulate, process, and manage data.
Package acc provides an accumulator mechanism to accumulate, process, and manage data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accumulator ¶
type Accumulator[T interface{}] interface { // Add adds a new item to the accumulator and returns its ID. Add(T) (string, error) // Cancel removes an item from the accumulator based on the provided ID. Cancel(string) error // Start initiates the accumulator to process accumulated data. Start() error }
Accumulator defines the interface for the accumulator mechanism.
func New ¶
func New[T any](cnf Config[T]) Accumulator[T]
New initializes a new accumulator instance based on the provided configuration. If no storage is provided, it defaults to an in-memory storage. If no interval is provided, it defaults to 15 minutes.
type Config ¶
type Config[T interface{}] struct { // Processor is a function to process accumulated items. Processor ProcessorFunc[T] // Storage represents the storage mechanism to save and load data items. Storage DataStorage[Data[T]] // Interval specifies the time interval at which the accumulator processes accumulated data. Interval time.Duration // StartTime sets the specific time when the accumulator should start processing. // If set, the accumulator waits until the specified time to begin processing. StartTime time.Time }
Config defines the configuration structure for the accumulator mechanism. It encapsulates the required parameters to initialize an accumulator.
type Data ¶
type Data[T interface{}] struct { Original T ID string }
Data represents a generic data structure with an original value and an ID.
type DataStorage ¶
type DataStorage[T interface{}] interface { // Save stores the provided data items. Save(data []T) error // Load retrieves the stored data items. Load() ([]T, error) }
DataStorage defines the interface for any storage mechanism to save and load data.
type InMemoryStorage ¶
type InMemoryStorage[T any] struct { // contains filtered or unexported fields }
InMemoryStorage is an in-memory storage implementation for the DataStorage interface.
func NewInMemoryStorage ¶
func NewInMemoryStorage[T any]() *InMemoryStorage[T]
NewInMemoryStorage initializes a new instance of InMemoryStorage.
func (*InMemoryStorage[T]) Load ¶
func (s *InMemoryStorage[T]) Load() ([]Data[T], error)
Load retrieves the stored data items from memory.
func (*InMemoryStorage[T]) Save ¶
func (s *InMemoryStorage[T]) Save(data []Data[T]) error
Save stores the provided data items in memory.
type ProcessorFunc ¶
type ProcessorFunc[T interface{}] func(data []T)
ProcessorFunc defines the function signature for processing data.