Skip to content

Commit ea8f831

Browse files
committed
✨ feat: Update session middleware add Keys method and update docs to match key type any
1 parent b29171c commit ea8f831

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

docs/middleware/session.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ func DefaultErrorHandler(fiber.Ctx, err error)
194194
### Middleware Methods
195195

196196
```go
197-
func (m *Middleware) Set(key string, value any)
198-
func (m *Middleware) Get(key string) any
199-
func (m *Middleware) Delete(key string)
197+
func (m *Middleware) Set(key any, value any)
198+
func (m *Middleware) Get(key any) any
199+
func (m *Middleware) Delete(key any)
200+
func (m *Middleware) Keys() []any
200201
func (m *Middleware) Destroy() error
201202
func (m *Middleware) Reset() error
202203
func (m *Middleware) Store() *Store
@@ -207,14 +208,15 @@ func (m *Middleware) Store() *Store
207208
```go
208209
func (s *Session) Fresh() bool
209210
func (s *Session) ID() string
210-
func (s *Session) Get(key string) any
211-
func (s *Session) Set(key string, val any)
211+
func (s *Session) Get(key any) any
212+
func (s *Session) Set(key any, val any)
213+
func (s *Session) Delete(key any)
214+
func (s *Session) Keys() []any
212215
func (s *Session) Destroy() error
213216
func (s *Session) Regenerate() error
214217
func (s *Session) Release()
215218
func (s *Session) Reset() error
216219
func (s *Session) Save() error
217-
func (s *Session) Keys() []string
218220
func (s *Session) SetIdleTimeout(idleTimeout time.Duration)
219221
```
220222

middleware/session/middleware.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@ func (m *Middleware) Delete(key any) {
232232
m.Session.Delete(key)
233233
}
234234

235+
// Keys returns all keys in the current session.
236+
//
237+
// Returns:
238+
// - []any: A slice of all keys in the session.
239+
//
240+
// Usage:
241+
//
242+
// keys := m.Keys()
243+
func (m *Middleware) Keys() []any {
244+
m.mu.RLock()
245+
defer m.mu.RUnlock()
246+
247+
return m.Session.Keys()
248+
}
249+
235250
// Destroy destroys the session.
236251
//
237252
// Returns:

middleware/session/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (s *Session) saveSession() error {
325325
// Keys retrieves all keys in the current session.
326326
//
327327
// Returns:
328-
// - []string: A slice of all keys in the session.
328+
// - []any: A slice of all keys in the session.
329329
//
330330
// Usage:
331331
//

0 commit comments

Comments
 (0)