From ee499f5c3e6c0943f952f013d0232912719f9807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 15 Oct 2020 22:44:36 +0100 Subject: [PATCH] Made use of SetIDFromDatabaseKey --- z/database.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/z/database.go b/z/database.go index 307f6e7..3cc2ad7 100644 --- a/z/database.go +++ b/z/database.go @@ -4,7 +4,6 @@ import ( "os" "log" "errors" - "strings" "encoding/json" "github.com/tidwall/buntdb" "github.com/google/uuid" @@ -72,7 +71,9 @@ func (database *Database) GetEntry(user string, entryId string) (Entry, error) { dberr := database.DB.View(func(tx *buntdb.Tx) error { tx.AscendKeys(user + ":entry:" + entryId, func(key, value string) bool { json.Unmarshal([]byte(value), &entry) - entry.ID = (strings.Split(key, ":"))[2] + + entry.SetIDFromDatabaseKey(key) + return true }) @@ -137,7 +138,7 @@ func (database *Database) ListEntries() ([]Entry, error) { var entry Entry json.Unmarshal([]byte(value), &entry) - entry.ID = key + entry.SetIDFromDatabaseKey(key) entries = append(entries, entry) return true