valueholder

package
v0.0.0-...-a33ea14 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package valueholder provides a struct called ValueHolder that holds a value, its last update time, its last zero update time, and a zero value string. It also has a lock for synchronization (race condition prevention).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ValueHolder

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

ValueHolder is a ByteWriter that holds the byte value of the last data written to it. It provides methods to read and update the value, as well as to retrieve its last update time and zero update time. The lock field is used to synchronize access to the data field and prevent race conditions.

func NewValueHolder

func NewValueHolder(zero string) *ValueHolder

NewValueHolder creates a new instance of ValueHolder with the provided zero value. It initializes the data field with an empty slice, the lastUpdate and lastZero fields with the current time, and the zero field with the provided zero value.

func (*ValueHolder) String

func (v *ValueHolder) String() string

String returns the current value of the ValueHolder as a string. It acquires a lock before reading the data field and releases it afterwards.

func (*ValueHolder) ToMap

func (v *ValueHolder) ToMap() map[string]any

ToMap returns a map containing the current value, whether it's zero, the last update time, and the last zero update time, formatted according to RFC3339.

func (*ValueHolder) Write

func (v *ValueHolder) Write(p []byte) (n int, err error)

Write updates the current value of the ValueHolder with the provided data slice. It acquires a lock before updating the data field, the lastUpdate field, and releases it afterwards. If the new value is equal to the zero value, it updates the lastZero field with the current time.

Jump to

Keyboard shortcuts

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