github.com/gogf/gf/v2@v2.7.4/os/gsession/gsession_storage_base.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gsession 8 9 import ( 10 "context" 11 "time" 12 13 "github.com/gogf/gf/v2/container/gmap" 14 ) 15 16 // StorageBase is a base implement for Session Storage. 17 type StorageBase struct{} 18 19 // New creates a session id. 20 // This function can be used for custom session creation. 21 func (s *StorageBase) New(ctx context.Context, ttl time.Duration) (id string, err error) { 22 return "", ErrorDisabled 23 } 24 25 // Get retrieves certain session value with given key. 26 // It returns nil if the key does not exist in the session. 27 func (s *StorageBase) Get(ctx context.Context, sessionId string, key string) (value interface{}, err error) { 28 return nil, ErrorDisabled 29 } 30 31 // Data retrieves all key-value pairs as map from storage. 32 func (s *StorageBase) Data(ctx context.Context, sessionId string) (sessionData map[string]interface{}, err error) { 33 return nil, ErrorDisabled 34 } 35 36 // GetSize retrieves the size of key-value pairs from storage. 37 func (s *StorageBase) GetSize(ctx context.Context, sessionId string) (size int, err error) { 38 return 0, ErrorDisabled 39 } 40 41 // Set sets key-value session pair to the storage. 42 // The parameter `ttl` specifies the TTL for the session id (not for the key-value pair). 43 func (s *StorageBase) Set(ctx context.Context, sessionId string, key string, value interface{}, ttl time.Duration) error { 44 return ErrorDisabled 45 } 46 47 // SetMap batch sets key-value session pairs with map to the storage. 48 // The parameter `ttl` specifies the TTL for the session id(not for the key-value pair). 49 func (s *StorageBase) SetMap(ctx context.Context, sessionId string, mapData map[string]interface{}, ttl time.Duration) error { 50 return ErrorDisabled 51 } 52 53 // Remove deletes key with its value from storage. 54 func (s *StorageBase) Remove(ctx context.Context, sessionId string, key string) error { 55 return ErrorDisabled 56 } 57 58 // RemoveAll deletes session from storage. 59 func (s *StorageBase) RemoveAll(ctx context.Context, sessionId string) error { 60 return ErrorDisabled 61 } 62 63 // GetSession returns the session data as *gmap.StrAnyMap for given session id from storage. 64 // 65 // The parameter `ttl` specifies the TTL for this session, and it returns nil if the TTL is exceeded. 66 // The parameter `data` is the current old session data stored in memory, 67 // and for some storage it might be nil if memory storage is disabled. 68 // 69 // This function is called ever when session starts. 70 func (s *StorageBase) GetSession(ctx context.Context, sessionId string, ttl time.Duration) (*gmap.StrAnyMap, error) { 71 return nil, ErrorDisabled 72 } 73 74 // SetSession updates the data map for specified session id. 75 // This function is called ever after session, which is changed dirty, is closed. 76 // This copy all session data map from memory to storage. 77 func (s *StorageBase) SetSession(ctx context.Context, sessionId string, sessionData *gmap.StrAnyMap, ttl time.Duration) error { 78 return ErrorDisabled 79 } 80 81 // UpdateTTL updates the TTL for specified session id. 82 // This function is called ever after session, which is not dirty, is closed. 83 // It just adds the session id to the async handling queue. 84 func (s *StorageBase) UpdateTTL(ctx context.Context, sessionId string, ttl time.Duration) error { 85 return ErrorDisabled 86 }