From c994959f736206aacec8e9933d62588b9cb5b0c5 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Sun, 21 Mar 2021 21:44:19 +0300 Subject: redisign --- internal/storer/storer.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'internal/storer') 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 +} -- cgit v1.2.3