diff --git a/internel/storage/sqlite/sqlite.go b/internel/storage/sqlite/sqlite.go index 4dd8ace..3803ca8 100644 --- a/internel/storage/sqlite/sqlite.go +++ b/internel/storage/sqlite/sqlite.go @@ -95,13 +95,18 @@ func (s *StorageSqlite) Get(id string) (*storage.Paste, error) { if err != nil { return nil, err } + rows, err := stmt.Query(id) + if err != nil { + return nil, err + } var p storage.Paste if !rows.Next() { return nil, nil } + defer rows.Close() var plain = 0 diff --git a/internel/storage/sqlite_test.go b/internel/storage/sqlite_test.go index 14d9585..0e21c54 100644 --- a/internel/storage/sqlite_test.go +++ b/internel/storage/sqlite_test.go @@ -62,7 +62,7 @@ func testGetSave(s *sqlite.StorageSqlite, t * testing.T) { t.Fatalf("Purged %v rows, expect 1 row", affected) } - var p_a, _ *storage.Paste + var p_a, p_b, _ *storage.Paste if p_a, err = s.Get(id_a); err != nil { t.Fatalf("Fatal on Get a: %v", err) @@ -71,8 +71,7 @@ func testGetSave(s *sqlite.StorageSqlite, t * testing.T) { t.Fatal("Content not match") } } - if _, err = s.Get(id_b); err == nil { + if p_b, err = s.Get(id_b); err == nil && p_b != nil { t.Fatalf("Fatal on Get b, it shoud have been purged") - } } diff --git a/internel/storage/storage.go b/internel/storage/storage.go index 95ac370..75d6c02 100644 --- a/internel/storage/storage.go +++ b/internel/storage/storage.go @@ -1,7 +1,7 @@ package storage type Storage interface { - Save(Paste) (string, error) + Save(*Paste) (string, error) Get(string) (*Paste, error) Purge() (int64, error) }