From 623eaf165a4f248681acfec094f2f1ac1e0ff89f Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Tue, 30 Jul 2024 00:45:25 +0300 Subject: Пересмотрел механизм сессий MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/session/bbolt.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'middleware/session/bbolt.go') diff --git a/middleware/session/bbolt.go b/middleware/session/bbolt.go index be484d7..bf46953 100644 --- a/middleware/session/bbolt.go +++ b/middleware/session/bbolt.go @@ -2,7 +2,6 @@ package session import ( "bytes" - "context" "encoding/gob" "log/slog" @@ -21,8 +20,8 @@ type BoltStore struct { bucketName []byte } -func (s *BoltStore) Load(ctx context.Context, sessionID string) Value { - v := Value{} +func (s *BoltStore) Load(sessionID string) Values { + v := Values{} err := s.db.View(func(tx *bbolt.Tx) error { bucket := tx.Bucket(s.bucketName) if bucket == nil { @@ -39,12 +38,12 @@ func (s *BoltStore) Load(ctx context.Context, sessionID string) Value { return gob.NewDecoder(rdr).Decode(&v) }) if err != nil { - slog.WarnContext(ctx, "failed load session", slog.Any("error", err)) + slog.Warn("failed load session", slog.Any("error", err)) } return v } -func (s *BoltStore) Save(ctx context.Context, sessionID string, value Value) error { +func (s *BoltStore) Save(sessionID string, value Values) error { return s.db.Update(func(tx *bbolt.Tx) error { bucket, err := tx.CreateBucketIfNotExists(s.bucketName) if err != nil { @@ -59,7 +58,7 @@ func (s *BoltStore) Save(ctx context.Context, sessionID string, value Value) err }) } -func (s *BoltStore) Remove(ctx context.Context, sessionID string) error { +func (s *BoltStore) Remove(sessionID string) error { return s.db.Update(func(tx *bbolt.Tx) error { bucket, err := tx.CreateBucketIfNotExists(s.bucketName) if err != nil { -- cgit v1.2.3