Decode binds the "outPtr" to the value associated to the provided "key".
(sid, key string, outPtr interface{})
| 292 | |
| 293 | // Decode binds the "outPtr" to the value associated to the provided "key". |
| 294 | func (db *Database) Decode(sid, key string, outPtr interface{}) error { |
| 295 | err := db.Service.View(func(tx *bolt.Tx) error { |
| 296 | b := db.getBucketForSession(tx, sid) |
| 297 | if b == nil { |
| 298 | return nil |
| 299 | } |
| 300 | |
| 301 | valueBytes := b.Get(makeKey(key)) |
| 302 | if len(valueBytes) == 0 { |
| 303 | return nil |
| 304 | } |
| 305 | |
| 306 | return sessions.DefaultTranscoder.Unmarshal(valueBytes, outPtr) |
| 307 | }) |
| 308 | if err != nil { |
| 309 | db.logger.Debugf("session '%s' key '%s' cannot be retrieved: %v", sid, key, err) |
| 310 | } |
| 311 | |
| 312 | return err |
| 313 | } |
| 314 | |
| 315 | // Visit loops through all session keys and values. |
| 316 | func (db *Database) Visit(sid string, cb func(key string, value interface{})) error { |