Skip to content

Commit b709975

Browse files
authored
Merge pull request #2 from Knifechik/feat/add-interfaces
feat: fix
2 parents 9121cdf + 6e5da61 commit b709975

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

data_storage.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ func (d *dataStorage[K, V]) Set(userID int64, key K, value V) error {
3535
}
3636

3737
// Get gets user's data from data storage
38-
func (d *dataStorage[K, V]) Get(userID int64, key K) (any, error) {
38+
func (d *dataStorage[K, V]) Get(userID int64, key K) (V, error) {
3939
d.mu.Lock()
4040
defer d.mu.Unlock()
4141

4242
if _, ok := d.Storage[userID]; !ok {
43-
return nil, fmt.Errorf("%w, userID:%d, comparable:%v", errNoUserData, userID, key)
43+
var empty V
44+
return empty, fmt.Errorf("%w, userID:%d, comparable:%v", errNoUserData, userID, key)
4445
}
4546

4647
return d.Storage[userID][key], nil

fsm.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type UserStateStorage interface {
2929
// DataStorage is an interface for data storage
3030
type DataStorage[K comparable, V any] interface {
3131
Set(userID int64, key K, value V) error
32-
Get(userID int64, key K) (any, error)
32+
Get(userID int64, key K) (V, error)
3333
Delete(userID int64, key K) error
3434
}
3535

@@ -122,10 +122,11 @@ func (f *FSM[K, V]) Set(userID int64, key K, value V) error {
122122
}
123123

124124
// Get gets a value from data storage by userID and comparable
125-
func (f *FSM[K, V]) Get(userID int64, key K) (any, error) {
125+
func (f *FSM[K, V]) Get(userID int64, key K) (V, error) {
126126
v, err := f.storage.Get(userID, key)
127127
if err != nil {
128-
return nil, fmt.Errorf("failed to get user data: %w", err)
128+
var empty V
129+
return empty, fmt.Errorf("failed to get user data: %w", err)
129130
}
130131

131132
return v, nil

0 commit comments

Comments
 (0)