Skip to content

Commit

Permalink
refactor(middleware/session): Update session middleware Set, Get, and…
Browse files Browse the repository at this point in the history
… Delete methods

Refactor the Set, Get, and Delete methods in the session middleware to use more descriptive parameter names. Instead of using "middlewareContextKey", the methods now use "key" to represent the key of the session value. This improves the readability and clarity of the code.
  • Loading branch information
sixcolors committed Sep 25, 2024
1 parent 7765ee5 commit 8716c95
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions middleware/session/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ func FromContext(c fiber.Ctx) *Middleware {
// Usage:
//
// m.Set("key", "value")
func (m *Middleware) Set(middlewareContextKey string, value any) {
func (m *Middleware) Set(key string, value any) {
m.mu.Lock()
defer m.mu.Unlock()

m.Session.Set(middlewareContextKey, value)
m.Session.Set(key, value)
}

// Get retrieves a value from the session by key.
Expand All @@ -213,11 +213,11 @@ func (m *Middleware) Set(middlewareContextKey string, value any) {
// Usage:
//
// value := m.Get("key")
func (m *Middleware) Get(middlewareContextKey string) any {
func (m *Middleware) Get(key string) any {
m.mu.RLock()
defer m.mu.RUnlock()

return m.Session.Get(middlewareContextKey)
return m.Session.Get(key)
}

// Delete removes a key-value pair from the session.
Expand All @@ -228,11 +228,11 @@ func (m *Middleware) Get(middlewareContextKey string) any {
// Usage:
//
// m.Delete("key")
func (m *Middleware) Delete(middlewareContextKey string) {
func (m *Middleware) Delete(key string) {
m.mu.Lock()
defer m.mu.Unlock()

m.Session.Delete(middlewareContextKey)
m.Session.Delete(key)
}

// Destroy destroys the session.
Expand Down

0 comments on commit 8716c95

Please sign in to comment.