summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--storage.go19
1 files changed, 18 insertions, 1 deletions
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