Commit 1b9835ad authored by Ivar Derksen's avatar Ivar Derksen Committed by Sietse Ringers
Browse files

Use type string as key type in bbolt

parent 04bb9d55
...@@ -56,40 +56,32 @@ func (s *storage) EnsureStorageExists() error { ...@@ -56,40 +56,32 @@ func (s *storage) EnsureStorageExists() error {
return err return err
} }
func (s *storage) txStore(tx *bbolt.Tx, key interface{}, value interface{}, bucketName string) error { func (s *storage) txStore(tx *bbolt.Tx, key string, value interface{}, bucketName string) error {
b, err := tx.CreateBucketIfNotExists([]byte(bucketName)) b, err := tx.CreateBucketIfNotExists([]byte(bucketName))
if err != nil { if err != nil {
return err return err
} }
btsKey, err := json.Marshal(key)
if err != nil {
return err
}
btsValue, err := json.Marshal(value) btsValue, err := json.Marshal(value)
if err != nil { if err != nil {
return err return err
} }
return b.Put(btsKey, btsValue) return b.Put([]byte(key), btsValue)
} }
func (s *storage) txLoad(tx *bbolt.Tx, key interface{}, dest interface{}, bucketName string) (found bool, err error) { func (s *storage) txLoad(tx *bbolt.Tx, key string, dest interface{}, bucketName string) (found bool, err error) {
b := tx.Bucket([]byte(bucketName)) b := tx.Bucket([]byte(bucketName))
if b == nil { if b == nil {
return false, nil return false, nil
} }
btsKey, err := json.Marshal(key) bts := b.Get([]byte(key))
if err != nil {
return false, err
}
bts := b.Get(btsKey)
if bts == nil { if bts == nil {
return false, nil return false, nil
} }
return true, json.Unmarshal(bts, dest) return true, json.Unmarshal(bts, dest)
} }
func (s *storage) load(key interface{}, dest interface{}, bucketName string) (found bool, err error) { func (s *storage) load(key string, dest interface{}, bucketName string) (found bool, err error) {
err = s.db.View(func(tx *bbolt.Tx) error { err = s.db.View(func(tx *bbolt.Tx) error {
found, err = s.txLoad(tx, key, dest, bucketName) found, err = s.txLoad(tx, key, dest, bucketName)
return err return err
...@@ -262,14 +254,9 @@ func (s *storage) LoadAttributes() (list map[irma.CredentialTypeIdentifier][]*ir ...@@ -262,14 +254,9 @@ func (s *storage) LoadAttributes() (list map[irma.CredentialTypeIdentifier][]*ir
return nil return nil
} }
return b.ForEach(func(key, value []byte) error { return b.ForEach(func(key, value []byte) error {
var ( credTypeID := irma.NewCredentialTypeIdentifier(string(key))
credTypeID irma.CredentialTypeIdentifier
attrlistlist []*irma.AttributeList var attrlistlist []*irma.AttributeList
)
err := json.Unmarshal(key, &credTypeID)
if err != nil {
return err
}
err = json.Unmarshal(value, &attrlistlist) err = json.Unmarshal(value, &attrlistlist)
if err != nil { if err != nil {
return err return err
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment