From 06074d25c7458c27480b36697d16ef8705795ce8 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 26 Apr 2021 23:44:25 +0200 Subject: Added details to recent battles --- storage.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/storage.go b/storage.go index 9172e96..75108ac 100644 --- a/storage.go +++ b/storage.go @@ -50,6 +50,19 @@ func (b *Battle) CalculateHash() { b.Id = hex.EncodeToString(sum[:]) } +func (s *Storage) LoadBattle(battle *Battle) error { + stream, err := os.Open(s.Path + "/battles/" + battle.Id) + if err != nil { + return err + } + decoder := json.NewDecoder(stream) + if err = decoder.Decode(battle); err != nil { + return err + } + + return nil +} + func (s *Storage) AddBattle(battle *Battle) error { if len(battle.Killmails) < 1 { return errors.New("missing killmails") @@ -81,7 +94,11 @@ func (s *Storage) ListRecentBattles(count int) ([]Battle, error) { battles := make([]Battle, 0, count) for i := 0; i < count && i < len(files); i++ { - battles = append(battles, Battle{Id: files[i].Name(), LastModified: files[i].ModTime()}) + battle := Battle{Id: files[i].Name(), LastModified: files[i].ModTime()} + if err = s.LoadBattle(&battle); err != nil { + return nil, err + } + battles = append(battles, battle) } return battles, nil -- cgit v1.1