mirror of https://github.com/gofiber/fiber.git
update
parent
1dbd1cc1d5
commit
804e8f8b75
|
@ -14,7 +14,7 @@ Below is the detailed description of all public methods and usage examples.
|
|||
// State is a key-value store for Fiber's app in order to be used as a global storage for the app's dependencies.
|
||||
// It's a thread-safe implementation of a map[string]any, using sync.Map.
|
||||
type State struct {
|
||||
dependencies sync.Map
|
||||
dependencies sync.Map
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -377,7 +377,7 @@ func main() {
|
|||
|
||||
// Check the Redis connection.
|
||||
if err := rdb.Ping(ctx).Err(); err != nil {
|
||||
log.Fatalf("Could not connect to Redis: %v", err)
|
||||
log.Fatalf("Could not connect to Redis: %v", err)
|
||||
}
|
||||
|
||||
// Inject the Redis client into Fiber's State for dependency injection.
|
||||
|
@ -426,4 +426,4 @@ func main() {
|
|||
|
||||
app.Listen(":3000")
|
||||
}
|
||||
```
|
||||
```
|
||||
|
|
|
@ -247,15 +247,15 @@ func Test_GetStateWithDefault(t *testing.T) {
|
|||
st := newState()
|
||||
|
||||
st.Set("flag", true)
|
||||
flag := GetStateWithDefault[bool](st, "flag", false)
|
||||
flag := GetStateWithDefault(st, "flag", false)
|
||||
require.True(t, flag)
|
||||
|
||||
// mismatched type should return the default value
|
||||
str := GetStateWithDefault[string](st, "flag", "default")
|
||||
str := GetStateWithDefault(st, "flag", "default")
|
||||
require.Equal(t, "default", str)
|
||||
|
||||
// missing key should return the default value
|
||||
flag = GetStateWithDefault[bool](st, "missing", false)
|
||||
flag = GetStateWithDefault(st, "missing", false)
|
||||
require.False(t, flag)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue