* replace interface{} with any
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-07-05 09:46:50 +03:00
коммит произвёл GitHub
родитель b45ff0be5d
Коммит 717a4d04a9
258 изменённых файлов: 1286 добавлений и 1286 удалений

8
services/cache/cache.go поставляемый
Просмотреть файл

@@ -20,19 +20,19 @@ type Cache interface {
// Set adds the given key and value to the store without an expiry. If the key already exists,
// it will overwrite the previous value.
Set(key string, value interface{}) error
Set(key string, value any) error
// SetWithDefaultExpiry adds the given key and value to the store with the default expiry. If
// the key already exists, it will overwrite the previous value
SetWithDefaultExpiry(key string, value interface{}) error
SetWithDefaultExpiry(key string, value any) error
// SetWithExpiry adds the given key and value to the cache with the given expiry. If the key
// already exists, it will overwrite the previous value
SetWithExpiry(key string, value interface{}, ttl time.Duration) error
SetWithExpiry(key string, value any, ttl time.Duration) error
// Get the content stored in the cache for the given key, and decode it into the value interface.
// Return ErrKeyNotFound if the key is missing from the cache
Get(key string, value interface{}) error
Get(key string, value any) error
// Remove deletes the value for a given key.
Remove(key string) error

12
services/cache/lru.go поставляемый
Просмотреть файл

@@ -70,25 +70,25 @@ func (l *LRU) Purge() error {
// Set adds the given key and value to the store without an expiry. If the key already exists,
// it will overwrite the previous value.
func (l *LRU) Set(key string, value interface{}) error {
func (l *LRU) Set(key string, value any) error {
return l.SetWithExpiry(key, value, 0)
}
// SetWithDefaultExpiry adds the given key and value to the store with the default expiry. If
// the key already exists, it will overwrite the previous value
func (l *LRU) SetWithDefaultExpiry(key string, value interface{}) error {
func (l *LRU) SetWithDefaultExpiry(key string, value any) error {
return l.SetWithExpiry(key, value, l.defaultExpiry)
}
// SetWithExpiry adds the given key and value to the cache with the given expiry. If the key
// already exists, it will overwrite the previous value
func (l *LRU) SetWithExpiry(key string, value interface{}, ttl time.Duration) error {
func (l *LRU) SetWithExpiry(key string, value any, ttl time.Duration) error {
return l.set(key, value, ttl)
}
// Get the content stored in the cache for the given key, and decode it into the value interface.
// return ErrKeyNotFound if the key is missing from the cache
func (l *LRU) Get(key string, value interface{}) error {
func (l *LRU) Get(key string, value any) error {
return l.get(key, value)
}
@@ -137,7 +137,7 @@ func (l *LRU) Name() string {
return l.name
}
func (l *LRU) set(key string, value interface{}, ttl time.Duration) error {
func (l *LRU) set(key string, value any, ttl time.Duration) error {
var expires time.Time
if ttl > 0 {
expires = time.Now().Add(ttl)
@@ -184,7 +184,7 @@ func (l *LRU) set(key string, value interface{}, ttl time.Duration) error {
return nil
}
func (l *LRU) get(key string, value interface{}) error {
func (l *LRU) get(key string, value any) error {
val, err := l.getItem(key)
if err != nil {
return err

8
services/cache/lru_striped.go поставляемый
Просмотреть файл

@@ -63,22 +63,22 @@ func (L LRUStriped) Purge() error {
}
// Set does the same as LRU.Set
func (L LRUStriped) Set(key string, value interface{}) error {
func (L LRUStriped) Set(key string, value any) error {
return L.keyBucket(key).Set(key, value)
}
// SetWithDefaultExpiry does the same as LRU.SetWithDefaultExpiry
func (L LRUStriped) SetWithDefaultExpiry(key string, value interface{}) error {
func (L LRUStriped) SetWithDefaultExpiry(key string, value any) error {
return L.keyBucket(key).SetWithDefaultExpiry(key, value)
}
// SetWithExpiry does the same as LRU.SetWithExpiry
func (L LRUStriped) SetWithExpiry(key string, value interface{}, ttl time.Duration) error {
func (L LRUStriped) SetWithExpiry(key string, value any, ttl time.Duration) error {
return L.keyBucket(key).SetWithExpiry(key, value, ttl)
}
// Get does the same as LRU.Get
func (L LRUStriped) Get(key string, value interface{}) error {
func (L LRUStriped) Get(key string, value any) error {
return L.keyBucket(key).Get(key, value)
}

8
services/cache/lru_test.go поставляемый
Просмотреть файл

@@ -112,7 +112,7 @@ func TestLRUMarshalUnMarshal(t *testing.T) {
InvalidateClusterEvent: "",
})
value1 := map[string]interface{}{
value1 := map[string]any{
"key1": 1,
"key2": "value2",
}
@@ -120,7 +120,7 @@ func TestLRUMarshalUnMarshal(t *testing.T) {
require.NoError(t, err)
var value2 map[string]interface{}
var value2 map[string]any
err = l.Get("test", &value2)
require.NoError(t, err)
assert.EqualValues(t, 1, value2["key1"])
@@ -143,7 +143,7 @@ func TestLRUMarshalUnMarshal(t *testing.T) {
Message: "OriginalId",
MessageSource: "MessageSource",
Type: "Type",
Props: map[string]interface{}{
Props: map[string]any{
"key": "val",
},
Hashtags: "Hashtags",
@@ -490,7 +490,7 @@ func BenchmarkLRU(b *testing.B) {
Message: "OriginalId",
MessageSource: "MessageSource",
Type: "Type",
Props: map[string]interface{}{
Props: map[string]any{
"key": "val",
},
Hashtags: "Hashtags",

16
services/cache/mocks/Cache.go поставляемый
Просмотреть файл

@@ -14,11 +14,11 @@ type Cache struct {
}
// Get provides a mock function with given fields: key, value
func (_m *Cache) Get(key string, value interface{}) error {
func (_m *Cache) Get(key string, value any) error {
ret := _m.Called(key, value)
var r0 error
if rf, ok := ret.Get(0).(func(string, interface{}) error); ok {
if rf, ok := ret.Get(0).(func(string, any) error); ok {
r0 = rf(key, value)
} else {
r0 = ret.Error(0)
@@ -128,11 +128,11 @@ func (_m *Cache) Remove(key string) error {
}
// Set provides a mock function with given fields: key, value
func (_m *Cache) Set(key string, value interface{}) error {
func (_m *Cache) Set(key string, value any) error {
ret := _m.Called(key, value)
var r0 error
if rf, ok := ret.Get(0).(func(string, interface{}) error); ok {
if rf, ok := ret.Get(0).(func(string, any) error); ok {
r0 = rf(key, value)
} else {
r0 = ret.Error(0)
@@ -142,11 +142,11 @@ func (_m *Cache) Set(key string, value interface{}) error {
}
// SetWithDefaultExpiry provides a mock function with given fields: key, value
func (_m *Cache) SetWithDefaultExpiry(key string, value interface{}) error {
func (_m *Cache) SetWithDefaultExpiry(key string, value any) error {
ret := _m.Called(key, value)
var r0 error
if rf, ok := ret.Get(0).(func(string, interface{}) error); ok {
if rf, ok := ret.Get(0).(func(string, any) error); ok {
r0 = rf(key, value)
} else {
r0 = ret.Error(0)
@@ -156,11 +156,11 @@ func (_m *Cache) SetWithDefaultExpiry(key string, value interface{}) error {
}
// SetWithExpiry provides a mock function with given fields: key, value, ttl
func (_m *Cache) SetWithExpiry(key string, value interface{}, ttl time.Duration) error {
func (_m *Cache) SetWithExpiry(key string, value any, ttl time.Duration) error {
ret := _m.Called(key, value, ttl)
var r0 error
if rf, ok := ret.Get(0).(func(string, interface{}, time.Duration) error); ok {
if rf, ok := ret.Get(0).(func(string, any, time.Duration) error); ok {
r0 = rf(key, value, ttl)
} else {
r0 = ret.Error(0)