Documentation
¶
Index ¶
- func Cache[K comparable, V any](buffer Buffer[K, V], key func(...any) K, function func(...any) V, ...) V
- func Fallback[T any](value T, err error) func(T) T
- func GetEnvBool(key string) (bool, error)
- func GetEnvFloat64(key string) (float64, error)
- func GetEnvInt(key string) (int, error)
- func GetEnvString(key string) (string, error)
- func Ignore[T any](value T, _ error) T
- func Must[T any](value T, err error) T
- func Ref[T any](value T) *T
- type Buffer
- type DefaultBuffer
- type TemporalBuffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cache ¶
func Cache[K comparable, V any](buffer Buffer[K, V], key func(...any) K, function func(...any) V, arguments ...any) V
Cache caches the function result into the buffer.
func Fallback ¶
Fallback returns the fallback value if error not nil.
Usage:
x := base.Fallback(time.ParseDuration("invalid_layout"))(10 * time.Second)
fmt.Printf("%v\n", x)
// Prints "10s".
func GetEnvBool ¶
GetEnvBool gets the bool from environment.
func GetEnvFloat64 ¶
GetEnvFloat64 gets the float64 from environment.
func GetEnvString ¶
GetEnvString gets the string from environment.
Types ¶
type Buffer ¶
type Buffer[K comparable, V any] interface { // Set sets the object into the buffer. Set(key K, value V) // Get gets the object from buffer. Get(key K) V // Delete removes the object from the buffer. Delete(key K) // Keys returns the buffer keys. Keys() []K }
Buffer is a buffer interface.
type DefaultBuffer ¶
type DefaultBuffer[K comparable, V any] struct { // contains filtered or unexported fields }
DefaultBuffer is a default buffer implementation.
func NewDefaultBuffer ¶
func NewDefaultBuffer[K comparable, V any]() *DefaultBuffer[K, V]
NewDefaultBuffer creates the buffer.
func NewDefaultBufferFrom ¶
func NewDefaultBufferFrom[K comparable, V any](data map[K]V) *DefaultBuffer[K, V]
NewDefaultBufferFrom creates the buffer with data.
func (*DefaultBuffer[K, V]) Delete ¶
func (buffer *DefaultBuffer[K, V]) Delete(key K)
Delete remove the object from the buffer.
func (*DefaultBuffer[K, V]) Get ¶
func (buffer *DefaultBuffer[K, V]) Get(key K) V
Get gets the object from the buffer.
func (*DefaultBuffer[K, V]) Keys ¶
func (buffer *DefaultBuffer[K, V]) Keys() []K
Map returns the buffer data.
func (*DefaultBuffer[K, V]) Set ¶
func (buffer *DefaultBuffer[K, V]) Set(key K, value V)
Set sets the object into the buffer.
type TemporalBuffer ¶
type TemporalBuffer[K comparable, V any] struct { // contains filtered or unexported fields }
TemporalBuffer is a temporal buffer implementation.
func NewTemporalBuffer ¶
func NewTemporalBuffer[K comparable, V any](duration time.Duration) *TemporalBuffer[K, V]
NewTemporalBuffer creates the buffer.
func NewTemporalBufferFrom ¶
func NewTemporalBufferFrom[K comparable, V any](data map[K]V, duration time.Duration) *TemporalBuffer[K, V]
NewTemporalBufferFrom creates the buffer with data.
func (*TemporalBuffer[K, V]) Delete ¶
func (buffer *TemporalBuffer[K, V]) Delete(key K)
Delete remove the object from the buffer.
func (*TemporalBuffer[K, V]) Get ¶
func (buffer *TemporalBuffer[K, V]) Get(key K) V
func (*TemporalBuffer[K, V]) Keys ¶
func (buffer *TemporalBuffer[K, V]) Keys() []K
Keys returns the buffer keys.
func (*TemporalBuffer[K, V]) Set ¶
func (buffer *TemporalBuffer[K, V]) Set(key K, value V)
Set sets the object into the buffer.