Fix nil pointer dereference and add filtering of skill queue

This commit is contained in:
Thomas Schwery 2017-01-30 19:10:33 +01:00
parent c1f48b56ed
commit 74e6f41998
2 changed files with 31 additions and 23 deletions

View file

@ -513,7 +513,7 @@ func (a *Client) PostUniverseNames(params *PostUniverseNamesParams) (*PostUniver
Method: "POST", Method: "POST",
PathPattern: "/universe/names/", PathPattern: "/universe/names/",
ProducesMediaTypes: []string{"application/json"}, ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{""}, ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"https"}, Schemes: []string{"https"},
Params: params, Params: params,
Reader: &PostUniverseNamesReader{formats: a.formats}, Reader: &PostUniverseNamesReader{formats: a.formats},

52
main.go
View file

@ -117,7 +117,7 @@ func getCharacterSkillQueue(client *http.Client, m *Character) {
skillMissingNames := make(map[int32]string) skillMissingNames := make(map[int32]string)
for _, skill := range skillqueue { for _, skill := range skillqueue {
skillName := getCachedData(fmt.Sprintf("%d.name", skill.SkillID)) skillName := getCachedData(fmt.Sprintf("%d.name", *skill.SkillID))
if skillName != "" { if skillName != "" {
skillNames[*skill.SkillID] = skillName skillNames[*skill.SkillID] = skillName
} else { } else {
@ -125,40 +125,48 @@ func getCharacterSkillQueue(client *http.Client, m *Character) {
} }
} }
snIds := make([]int32, 0, len(skillMissingNames)) if len(skillMissingNames) > 0 {
for skillID := range skillMissingNames { snIds := make([]int32, 0, len(skillMissingNames))
snIds = append(snIds, skillID) for skillID := range skillMissingNames {
} snIds = append(snIds, skillID)
}
var sncallParamBody ESIUniverse.PostUniverseNamesBody var sncallParamBody ESIUniverse.PostUniverseNamesBody
sncallParamBody.Ids = snIds sncallParamBody.Ids = snIds
sncallParam := ESIUniverse.NewPostUniverseNamesParams() sncallParam := ESIUniverse.NewPostUniverseNamesParams()
sncallParam.SetIds(sncallParamBody) sncallParam.SetIds(sncallParamBody)
skillNameResp, skillNameErr := swaggerclient.Universe.PostUniverseNames(sncallParam) skillNameResp, skillNameErr := swaggerclient.Universe.PostUniverseNames(sncallParam)
if skillNameErr != nil { if skillNameErr != nil {
log.Fatalf("Error on PostUniverseNames\n%s\n", skillNameErr) log.Fatalf("Error on PostUniverseNames\n%s\n", skillNameErr)
} }
for _, searchResult := range skillNameResp.Payload { for _, searchResult := range skillNameResp.Payload {
itemName := searchResult.Name itemName := searchResult.Name
itemID := searchResult.ID itemID := searchResult.ID
log.Printf("Got search result %d -> %s", *itemID, *itemName) putCacheData(fmt.Sprintf("%d.name", *itemID), *itemName)
putCacheData(fmt.Sprintf("%d.name", *itemID), *itemName) skillNames[*itemID] = *itemName
}
skillNames[*itemID] = *itemName
} }
for _, skill := range skillqueue { for _, skill := range skillqueue {
// element is the element from someSlice for where we are // element is the element from someSlice for where we are
name := skillNames[*skill.SkillID] name := skillNames[*skill.SkillID]
fmt.Printf(" %s: %d, level %d - %s to %s\n", finishDate := time.Time(skill.FinishDate)
// see https://github.com/ccpgames/esi-issues/issues/113
// The queue is only updated when the user logs in with the client
// we thus need to do the computations and filtering ourselves
if finishDate.Before(time.Now()) {
continue
}
fmt.Printf(" %s - level %d - %s to %s\n",
name, name,
*skill.SkillID,
*skill.FinishedLevel, *skill.FinishedLevel,
time.Time(skill.StartDate).Format("_2 Jan 2006, 15:04"), time.Time(skill.StartDate).Format("_2 Jan 2006, 15:04"),
time.Time(skill.FinishDate).Format("_2 Jan 2006, 15:04")) time.Time(skill.FinishDate).Format("_2 Jan 2006, 15:04"))