📦 update Storage behaviour

This commit is contained in:
Fenny 2020-10-31 07:51:44 +01:00
parent 8459618bfa
commit 7892ab62bf
5 changed files with 8 additions and 8 deletions

8
app.go
View File

@ -33,13 +33,16 @@ import (
// Version of current fiber package // Version of current fiber package
const Version = "2.1.2" const Version = "2.1.2"
// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) error
// Map is a shortcut for map[string]interface{}, useful for JSON returns // Map is a shortcut for map[string]interface{}, useful for JSON returns
type Map map[string]interface{} type Map map[string]interface{}
// Storage interface that is implemented by storage providers for different // Storage interface that is implemented by storage providers for different
// middleware packages like cache, limiter, session and csrf // middleware packages like cache, limiter, session and csrf
type Storage interface { type Storage interface {
// Get value by key. Error is returned if key does not exist // Get value by key, nil is returned if either does not exist
Get(key string) ([]byte, error) Get(key string) ([]byte, error)
// Set key value. `exp` will be zero for no expiration. // Set key value. `exp` will be zero for no expiration.
@ -52,9 +55,6 @@ type Storage interface {
Clear() error Clear() error
} }
// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) error
// ErrorHandler defines a function that will process all errors // ErrorHandler defines a function that will process all errors
// returned from any handlers in the stack // returned from any handlers in the stack
// cfg := fiber.Config{} // cfg := fiber.Config{}

View File

@ -145,7 +145,7 @@ func New(config ...Config) fiber.Handler {
} }
// Only decode if we found an entry // Only decode if we found an entry
if len(storeEntry) > 0 { if storeEntry != nil {
// Decode bytes using msgp // Decode bytes using msgp
if _, err := entry.UnmarshalMsg(storeEntry); err != nil { if _, err := entry.UnmarshalMsg(storeEntry); err != nil {
return err return err

View File

@ -301,7 +301,7 @@ func (s testStore) Get(id string) ([]byte, error) {
val, ok := s.stmap[id] val, ok := s.stmap[id]
s.mutex.RUnlock() s.mutex.RUnlock()
if !ok { if !ok {
return []byte{}, nil return nil, nil
} else { } else {
return val, nil return val, nil
} }

View File

@ -159,7 +159,7 @@ func New(config ...Config) fiber.Handler {
return err return err
} }
// Only decode if we found an entry // Only decode if we found an entry
if len(storeEntry) > 0 { if storeEntry != nil {
// Decode bytes using msgp // Decode bytes using msgp
if _, err := entry.UnmarshalMsg(storeEntry); err != nil { if _, err := entry.UnmarshalMsg(storeEntry); err != nil {
return err return err

View File

@ -214,7 +214,7 @@ func (s testStore) Get(id string) ([]byte, error) {
val, ok := s.stmap[id] val, ok := s.stmap[id]
s.mutex.Unlock() s.mutex.Unlock()
if !ok { if !ok {
return []byte{}, nil return nil, nil
} else { } else {
return val, nil return val, nil
} }