✏ return nil for notfound

This commit is contained in:
Fenny
2020-11-23 09:30:50 +01:00
parent fd56bd28da
commit ab94351a60
35 changed files with 109 additions and 134 deletions

View File

@@ -2,7 +2,6 @@ package mysql
import (
"database/sql"
"errors"
"fmt"
"time"
@@ -23,11 +22,6 @@ type Storage struct {
sqlGC string
}
// ErrNotFound means that a get call did not find the requested key.
var ErrNotFound = errors.New("key not found")
var ErrKeyNotExist = ErrNotFound
var (
dropQuery = "DROP TABLE IF EXISTS %s;"
initQuery = []string{
@@ -102,7 +96,7 @@ var noRows = "sql: no rows in result set"
// Get value by key
func (s *Storage) Get(key string) ([]byte, error) {
if len(key) <= 0 {
return nil, ErrNotFound
return nil, nil
}
row := s.db.QueryRow(s.sqlSelect, key)
@@ -115,14 +109,14 @@ func (s *Storage) Get(key string) ([]byte, error) {
if err := row.Scan(&data, &exp); err != nil {
if err == sql.ErrNoRows {
return nil, ErrNotFound
return nil, nil
}
return nil, err
}
// If the expiration time has already passed, then return nil
if exp != 0 && exp <= time.Now().Unix() {
return nil, ErrNotFound
return nil, nil
}
return data, nil