1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-14 14:15:01 +00:00

📦 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
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
type Map map[string]interface{}
// Storage interface that is implemented by storage providers for different
// middleware packages like cache, limiter, session and csrf
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)
// Set key value. `exp` will be zero for no expiration.
@ -52,9 +55,6 @@ type Storage interface {
Clear() error
}
// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) error
// ErrorHandler defines a function that will process all errors
// returned from any handlers in the stack
// cfg := fiber.Config{}

View File

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

View File

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

View File

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

View File

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