util

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JSONSerializer iface.ConfigSerializer = &configSerializerJSON{}

JSONSerializer is a configuration serializer that encodes and decodes data in JSON format

Functions

func CompareConfig

func CompareConfig(current, latest map[string]iface.ConfigValue) []iface.ConfigChange

CompareConfig compares the config changes between the current and latest version of the configuration. It takes in two maps that contain the configurations as key-value pairs and returns a slice of ConfigChange which represent the differences between the two versions.

func ConfigMapToSyncMap

func ConfigMapToSyncMap(m map[string]iface.ConfigValue) *sync.Map

ConfigMapToSyncMap returns a new sync.Map object converted from a map[string]iface.ConfigValue.

func ConfigSyncMapToMap

func ConfigSyncMapToMap(m *sync.Map) map[string]iface.ConfigValue

ConfigSyncMapToMap is used to convert a sync.Map to a map[string]iface.ConfigValue.

func IncreaseCounter

func IncreaseCounter() int64

IncreaseCounter increases the counter by 1 and returns the new value. It's useful when you need a process-wide unique ID.

func JsonDecodeWithNumber

func JsonDecodeWithNumber(b []byte, v interface{}) error

JsonDecodeWithNumber decodes a JSON byte slice with the option to parse numbers as json.Number type. This function is useful when precision is important and dealing with large values.

func JsonInitializer

func JsonInitializer(allocator func() iface.ConfigValueItem) iface.ItemInitializer

JsonInitializer receives an allocator func which produces an empty Item object, and returns a function which fills a new Item object (by the allocator) with given json bytes.

func MustJsonMarshal

func MustJsonMarshal(v interface{}) []byte

MustJsonMarshal marshals the given interface into a JSON string. If the operation fails, it panics.

func MustJsonUnmarshal

func MustJsonUnmarshal(b []byte, v interface{})

MustJsonUnmarshal unmarshal the given json bytes into given interface; panics on failure.

Types

type FrequencyLimiter

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

FrequencyLimiter is used to limit the frequency of any action.

func NewFrequencyLimiter

func NewFrequencyLimiter(interval time.Duration, allowed int32) *FrequencyLimiter

NewFrequencyLimiter creates a new FrequencyLimiter with the given interval and allowed count.

func (*FrequencyLimiter) Allow

func (l *FrequencyLimiter) Allow() bool

Allow returns true if the action is allowed.

func (*FrequencyLimiter) Stop

func (l *FrequencyLimiter) Stop()

Stop stops the refresh of this limiter.

Jump to

Keyboard shortcuts

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