mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
✏ return nil for notfound
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user