MCPcopy
hub / github.com/gofiber/fiber / saveSessionWithContext

Method saveSessionWithContext

middleware/session/session.go:378–404  ·  view source on GitHub ↗

saveSessionWithContext encodes session data and saves it to storage using the provided context.

(ctx context.Context)

Source from the content-addressed store, hash-verified

376
377// saveSessionWithContext encodes session data and saves it to storage using the provided context.
378func (s *Session) saveSessionWithContext(ctx context.Context) error {
379 if s.data == nil {
380 return nil
381 }
382
383 s.mu.Lock()
384 defer s.mu.Unlock()
385
386 // Set idleTimeout if not already set
387 if s.idleTimeout <= 0 {
388 s.idleTimeout = s.config.IdleTimeout
389 }
390
391 // Update client cookie
392 s.setSession()
393
394 // Encode session data
395 s.data.RLock()
396 encodedBytes, err := s.encodeSessionData()
397 s.data.RUnlock()
398 if err != nil {
399 return fmt.Errorf("failed to encode data: %w", err)
400 }
401
402 // Pass copied bytes with session id to provider
403 return s.config.Storage.SetWithContext(ctx, s.id, encodedBytes, s.idleTimeout)
404}
405
406// Keys retrieves all keys in the current session.
407//

Callers 2

SaveWithContextMethod · 0.95
saveSessionMethod · 0.80

Calls 6

setSessionMethod · 0.95
encodeSessionDataMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65
ErrorfMethod · 0.65
SetWithContextMethod · 0.65

Tested by

no test coverage detected