From 526fd502bee3c3038544db243d5f23c122de0d76 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:04 +0100 Subject: [PATCH] Implemented SetIDFromDatabaseKey --- z/entry.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/z/entry.go b/z/entry.go index c033976..2d70a2a 100644 --- a/z/entry.go +++ b/z/entry.go @@ -2,6 +2,7 @@ package z import ( "errors" + "strings" "time" "fmt" "github.com/gookit/color" @@ -49,6 +50,17 @@ func NewEntry( return newEntry, nil } +func (entry *Entry) SetIDFromDatabaseKey(key string) (error) { + splitKey := strings.Split(key, ":") + + if len(splitKey) < 3 || len(splitKey) > 3 { + return errors.New("not a valid database key") + } + + entry.ID = splitKey[2] + return nil +} + func (entry *Entry) SetBeginFromString(begin string) (time.Time, error) { var beginTime time.Time var err error