diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-21 21:44:19 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-21 21:44:19 +0300 |
commit | c994959f736206aacec8e9933d62588b9cb5b0c5 (patch) | |
tree | a65a3061df93984ecdb0911c4d0582c353ca5035 /internal | |
parent | 37c250d538893ff8178bd9c9e4dde225a991ce76 (diff) |
Diffstat (limited to 'internal')
-rw-r--r-- | internal/storer/storer.go | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/internal/storer/storer.go b/internal/storer/storer.go index 99da8b8..96ca9be 100644 --- a/internal/storer/storer.go +++ b/internal/storer/storer.go @@ -6,8 +6,8 @@ import ( "time" "github.com/dgraph-io/badger" + "github.com/google/uuid" "github.com/neonxp/sendsafe/internal/encryption" - "github.com/rs/xid" ) type Store struct { @@ -49,10 +49,10 @@ func (s *Store) Save(text string, pin string, ttl int) (string, error) { return "", err } - id := xid.New() + id := uuid.New() err = s.db.Update(func(txn *badger.Txn) error { return txn.SetEntry(&badger.Entry{ - Key: id.Bytes(), + Key: []byte(id.String()), Value: buf.Bytes(), ExpiresAt: uint64(time.Now().Add(time.Duration(ttl) * time.Minute).Unix()), }) @@ -65,11 +65,7 @@ func (s *Store) IsEncrypted(id string) (bool, error) { var encrypted bool return encrypted, s.db.View(func(txn *badger.Txn) error { - uid, err := xid.FromString(id) - if err != nil { - return err - } - value, err := txn.Get(uid.Bytes()) + value, err := txn.Get([]byte(id)) if err != nil { return err } @@ -88,11 +84,7 @@ func (s *Store) Get(id string, pin string) (string, error) { var text string return text, s.db.Update(func(txn *badger.Txn) error { - uid, err := xid.FromString(id) - if err != nil { - return err - } - value, err := txn.Get(uid.Bytes()) + value, err := txn.Get([]byte(id)) if err != nil { return err } @@ -114,7 +106,7 @@ func (s *Store) Get(id string, pin string) (string, error) { return err } } - return txn.Delete(uid.Bytes()) + return txn.Delete([]byte(id)) }) } @@ -126,3 +118,7 @@ type memo struct { Text string Encrypted bool } + +func (m *memo) Read(p []byte) (n int, err error) { + panic("not implemented") // TODO: Implement +} |