mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
📦 update Storage behaviour
This commit is contained in:
parent
8459618bfa
commit
7892ab62bf
8
app.go
8
app.go
@ -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{}
|
||||||
|
2
middleware/cache/cache.go
vendored
2
middleware/cache/cache.go
vendored
@ -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
|
||||||
|
2
middleware/cache/cache_test.go
vendored
2
middleware/cache/cache_test.go
vendored
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user