diff options
-rw-r--r-- | esi.go | 35 | ||||
-rw-r--r-- | models.go | 16 | ||||
-rw-r--r-- | storage.go | 11 |
3 files changed, 62 insertions, 0 deletions
@@ -0,0 +1,35 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" +) + +func GetKillmail(id uint64, hash string) (EsiKillmail, error) { + r, err := http.Get(fmt.Sprintf("https://esi.evetech.net/latest/killmails/%d/%s/", id, hash)) + if err != nil { + return EsiKillmail{}, err + } + decoder := json.NewDecoder(r.Body) + var details EsiKillmail + if err := decoder.Decode(&details); err != nil { + return EsiKillmail{}, err + } + + return details, nil +} + +func GetSolarSystem(id int32) (EsiUniverseSystem, error) { + r, err := http.Get(fmt.Sprintf("https://esi.evetech.net/latest/universe/systems/%d/", id)) + if err != nil { + return EsiUniverseSystem{}, err + } + decoder := json.NewDecoder(r.Body) + var details EsiUniverseSystem + if err := decoder.Decode(&details); err != nil { + return EsiUniverseSystem{}, err + } + + return details, nil +} @@ -16,4 +16,20 @@ type Battle struct { LastModified time.Time `json:"-"` Teams [2]Team `json:"teams"` Killmails []Killmail `json:"killmails"` + Name string `json:"name"` +} + +type EsiKillmail struct { + SolarSystemId int32 `json:"solar_system_id"` + Victim struct { + Position struct { + X float64 `json:"x"` + Y float64 `json:"y"` + Z float64 `json:"z"` + } `json:"position"` + } `json:"victim"` +} + +type EsiUniverseSystem struct { + Name string `json:"name"` } @@ -5,6 +5,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "fmt" "io" "io/ioutil" "net/http" @@ -68,6 +69,16 @@ func (s *Storage) AddBattle(battle *Battle) error { return errors.New("missing killmails") } battle.CalculateHash() + killmail := battle.Killmails[0] + details, err := GetKillmail(killmail.Id, killmail.Hash) + if err != nil { + return err + } + system, err := GetSolarSystem(details.SolarSystemId) + if err != nil { + return err + } + battle.Name = fmt.Sprintf("Battle in %s", system.Name) data, err := json.Marshal(battle) if err != nil { return err |