single db with prefixes, dump/restore, blacklisting on user deletion

This commit is contained in:
ston1th 2018-09-23 23:56:12 +02:00
commit d4971cda89
20 changed files with 264 additions and 163 deletions

36
pkg/db/blacklist.go Normal file
View file

@ -0,0 +1,36 @@
package db
import "git.giftfish.de/ston1th/jwt/v3"
const blacklistPrefix = "blacklist/"
func (db *DB) Add(sig string, exp int64) error {
return db.store.Set(blacklistPrefix+sig, exp)
}
func (db *DB) Remove(sig string) error {
return db.store.Delete(blacklistPrefix + sig)
}
func (db *DB) Check(sig string) (ok bool) {
if db.store.Get(blacklistPrefix+sig, nil) == nil {
return true
}
return false
}
func (db *DB) Map() (list jwt.BlacklistMap, err error) {
list = make(jwt.BlacklistMap)
err = db.store.ForEach(func(k string, v []byte) error {
if trim, ok := hasTrimPrefix(k, blacklistPrefix); ok {
var exp int64
err := db.store.Unmarshal(v, &exp)
if err != nil {
return err
}
list[trim] = exp
}
return nil
})
return
}