AllCtx returns a map containing the token and data for all active (i.e. not expired) sessions in the SQLite3Store instance.
(ctx context.Context)
| 147 | // AllCtx returns a map containing the token and data for all active (i.e. |
| 148 | // not expired) sessions in the SQLite3Store instance. |
| 149 | func (p *SQLite3Store) AllCtx(ctx context.Context) (map[string][]byte, error) { |
| 150 | tx, err := p.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true}) |
| 151 | if err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | defer tx.Rollback() |
| 155 | |
| 156 | rows, err := tx.QueryContext(ctx, "SELECT token, data FROM sessions WHERE expiry > ?", nowJulianDay()) |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | defer rows.Close() |
| 161 | |
| 162 | sessions := make(map[string][]byte) |
| 163 | |
| 164 | for rows.Next() { |
| 165 | var ( |
| 166 | token string |
| 167 | data []byte |
| 168 | ) |
| 169 | |
| 170 | err = rows.Scan(&token, &data) |
| 171 | if err != nil { |
| 172 | return nil, err |
| 173 | } |
| 174 | |
| 175 | sessions[token] = data |
| 176 | } |
| 177 | |
| 178 | err = rows.Err() |
| 179 | if err != nil { |
| 180 | return nil, err |
| 181 | } |
| 182 | |
| 183 | if err = tx.Commit(); err != nil { |
| 184 | return nil, err |
| 185 | } |
| 186 | |
| 187 | return sessions, nil |
| 188 | } |
| 189 | |
| 190 | func (p *SQLite3Store) startCleanup(interval time.Duration) { |
| 191 | ticker := time.NewTicker(interval) |
no test coverage detected