From 1744ddfc8e3b020676724c63515b5b34f01cdcf3 Mon Sep 17 00:00:00 2001 From: parmaster Date: Tue, 28 May 2024 20:16:40 +0300 Subject: [PATCH] interface fixed - generic functions --- main.go | 6 +++--- main_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 2793c82..b935b55 100644 --- a/main.go +++ b/main.go @@ -26,9 +26,9 @@ type Cache[T any] struct { } // Cacher is an interface for cache -type Cacher interface { - Set(key string, value interface{}, ttl int64) error - Get(key string) (interface{}, error) +type Cacher[T any] interface { + Set(key string, value T, ttl time.Duration) error + Get(key string) (T, error) Has(key string) (bool, error) Del(key string) error Cleanup() diff --git a/main_test.go b/main_test.go index 8ec9753..4638092 100644 --- a/main_test.go +++ b/main_test.go @@ -15,11 +15,11 @@ type testItem struct { } func Test_SimpleTest_Mcache(t *testing.T) { - c := NewCache[string]() + var c Cacher[string] // linter:ignore S1021 + c = NewCache[string]() assert.NotNil(t, c) assert.IsType(t, &Cache[string]{}, c) - assert.NotNil(t, c.data) testItems := []testItem{ {"key0", "value0", time.Second * 0},