util

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 8 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFromValue

func BoolFromValue(v kv.Value, key string, defaultValue bool, opts Options) (bool, error)

BoolFromValue get a bool from kv.Value. If the value is nil, the default value is returned.

func Float64FromValue

func Float64FromValue(v kv.Value, key string, defaultValue float64, opts Options) (float64, error)

Float64FromValue gets a float64 from kv.Value. If the value is nil, the default value is returned.

func Int64FromValue

func Int64FromValue(v kv.Value, key string, defaultValue int64, opts Options) (int64, error)

Int64FromValue gets an int64 from kv.Value. If the value is nil, the default value is returned.

func StringArrayFromValue

func StringArrayFromValue(
	v kv.Value, key string, defaultValue []string, opts Options,
) ([]string, error)

StringArrayFromValue gets a string array from kv.Value. If the value is nil, the default value is returned.

func StringFromValue

func StringFromValue(v kv.Value, key string, defaultValue string, opts Options) (string, error)

StringFromValue gets a string from kv.Value. If the value is nil, the default value is returned.

func TimeFromValue

func TimeFromValue(
	v kv.Value, key string, defaultValue time.Time, opts Options,
) (time.Time, error)

TimeFromValue gets a time.Time from kv.Value. If the value is nil, the default value is returned.

func WatchAndUpdateAtomicBool

func WatchAndUpdateAtomicBool(
	store kv.Store,
	key string,
	property *atomic.Bool,
	defaultValue bool,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateAtomicBool sets up a watch with validation for an atomic bool property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateAtomicFloat64

func WatchAndUpdateAtomicFloat64(
	store kv.Store,
	key string,
	property *atomic.Float64,
	defaultValue float64,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateAtomicFloat64 sets up a watch with validation for an atomic float64 property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateAtomicInt64

func WatchAndUpdateAtomicInt64(
	store kv.Store,
	key string,
	property *atomic.Int64,
	defaultValue int64,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateAtomicInt64 sets up a watch with validation for an atomic int64 property. Anymalformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateAtomicString

func WatchAndUpdateAtomicString(
	store kv.Store,
	key string,
	property *atomic.String,
	defaultValue string,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateAtomicString sets up a watch with validation for an atomic string property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateBool

func WatchAndUpdateBool(
	store kv.Store,
	key string,
	property *bool,
	lock sync.Locker,
	defaultValue bool,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateBool sets up a watch with validation for a bool property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateDuration added in v0.14.0

func WatchAndUpdateDuration(
	store kv.Store,
	key string,
	property *time.Duration,
	lock sync.Locker,
	defaultValue time.Duration,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateDuration sets up a watch with validation for a time property. Any malformed, or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateFloat64

func WatchAndUpdateFloat64(
	store kv.Store,
	key string,
	property *float64,
	lock sync.Locker,
	defaultValue float64,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateFloat64 sets up a watch with validation for a float64 property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateGeneric added in v0.7.1

func WatchAndUpdateGeneric(
	store kv.Store,
	key string,
	genericGetFn GenericGetValueFn,
	genericUpdateFn GenericUpdateFn,
	lock sync.Locker,
	defaultValue interface{},
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateGeneric sets up a watch with validation for a generic property. Any malformed, or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateInt64

func WatchAndUpdateInt64(
	store kv.Store,
	key string,
	property *int64,
	lock sync.Locker,
	defaultValue int64,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateInt64 sets up a watch with validation for an int64 property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateString

func WatchAndUpdateString(
	store kv.Store,
	key string,
	property *string,
	lock sync.Locker,
	defaultValue string,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateString sets up a watch with validation for a string property. Any malformed or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateStringArray

func WatchAndUpdateStringArray(
	store kv.Store,
	key string,
	property *[]string,
	lock sync.Locker,
	defaultValue []string,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateStringArray sets up a watch with validation for a string array property. Any malformed, or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateStringArrayPointer

func WatchAndUpdateStringArrayPointer(
	store kv.Store,
	key string,
	property **[]string,
	lock sync.Locker,
	defaultValue *[]string,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateStringArrayPointer sets up a watch with validation for a string array pointer property. Any malformed, or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

func WatchAndUpdateTime

func WatchAndUpdateTime(
	store kv.Store,
	key string,
	property *time.Time,
	lock sync.Locker,
	defaultValue time.Time,
	opts Options,
) (kv.ValueWatch, error)

WatchAndUpdateTime sets up a watch with validation for a time property. Any malformed, or invalid updates are not applied. The default value is applied when the key does not exist in KV. The watch on the value is returned.

Types

type GenericGetValueFn added in v0.7.1

type GenericGetValueFn getValueFn

GenericGetValueFn runs when a watched value changes to translate the KV value to a concrete type.

type GenericUpdateFn added in v0.7.1

type GenericUpdateFn updateFn

GenericUpdateFn runs when a watched value changes and receives the output of the GenericGetValueFn.

type Options

type Options interface {
	// SetValidateFn sets the validation function applied to kv values.
	SetValidateFn(val ValidateFn) Options

	// ValidateFn returns the validation function applied to kv values.
	ValidateFn() ValidateFn

	// SetLogger sets the logger.
	SetLogger(val *zap.Logger) Options

	// Logger returns the logger.
	Logger() *zap.Logger
}

Options is a set of options for kv utility functions.

func NewOptions

func NewOptions() Options

NewOptions returns a new set of options for kv utility functions.

type ValidateFn

type ValidateFn func(interface{}) error

ValidateFn validates an update from KV.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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