feat: add entry's fields Create and LastUpdate

This commit is contained in:
Adrien Waksberg 2019-07-24 19:01:31 +02:00
parent 48a47144a1
commit be8d5dfe60
3 changed files with 15 additions and 8 deletions

View file

@ -10,6 +10,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
### Added ### Added
- Test build with travis - Test build with travis
- Add entry's fields Create and LastUpdate
### Changed ### Changed

View file

@ -24,14 +24,16 @@ import(
// Entry struct have the password informations // Entry struct have the password informations
type Entry struct { type Entry struct {
Name string `yaml:"name"` Name string
ID string `yaml:"id"` ID string
URI string `yaml:"uri"` URI string
User string `yaml:"login"` User string
Password string `yaml:"password"` Password string
OTP string `yaml:"otp"` OTP string
Group string `yaml:"group"` Group string
Comment string `yaml:"comment"` Comment string
Create int64
LastUpdate int64
} }
// Verify if the item have'nt error // Verify if the item have'nt error

View file

@ -21,6 +21,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"regexp" "regexp"
"time"
"sort" "sort"
"strings" "strings"
) )
@ -151,6 +152,8 @@ func (w *Wallet) AddEntry(entry Entry) error {
return fmt.Errorf("the id already exists in wallet, can't add the entry") return fmt.Errorf("the id already exists in wallet, can't add the entry")
} }
entry.Create = time.Now().Unix()
entry.LastUpdate = entry.Create
w.Entries = append(w.Entries, entry) w.Entries = append(w.Entries, entry)
return nil return nil
@ -180,6 +183,7 @@ func (w *Wallet) UpdateEntry(entry Entry) error {
return err return err
} }
entry.LastUpdate = time.Now().Unix()
for index, i := range w.Entries { for index, i := range w.Entries {
if entry.ID == i.ID { if entry.ID == i.ID {
w.Entries[index] = entry w.Entries[index] = entry