Handling of expired tokens in cache, additional formatting of skills

This commit is contained in:
Thomas Schwery 2017-01-30 22:56:49 +01:00
parent 74e6f41998
commit 4bdd6ac706

22
main.go
View file

@ -66,7 +66,15 @@ func main() {
client := googleOauthConfig.Client(oauth2.NoContext, cToken) client := googleOauthConfig.Client(oauth2.NoContext, cToken)
m := getCharacterInfo(client) m, err := getCharacterInfo(client)
if err != nil {
cToken = getNewAuthorizationToken()
client = googleOauthConfig.Client(oauth2.NoContext, cToken)
m, err = getCharacterInfo(client)
if err != nil {
log.Fatal(err)
}
}
fmt.Printf("Name: %s\n", m.CharacterName) fmt.Printf("Name: %s\n", m.CharacterName)
fmt.Printf("Id: %d\n", m.CharacterID) fmt.Printf("Id: %d\n", m.CharacterID)
@ -75,13 +83,12 @@ func main() {
getCharacterSkillQueue(client, m) getCharacterSkillQueue(client, m)
} }
func getCharacterInfo(client *http.Client) *Character { func getCharacterInfo(client *http.Client) (*Character, error) {
req, _ := http.NewRequest("GET", "https://login.eveonline.com/oauth/verify", nil) req, _ := http.NewRequest("GET", "https://login.eveonline.com/oauth/verify", nil)
response, errDo := client.Do(req) response, errDo := client.Do(req)
if errDo != nil { if errDo != nil {
fmt.Printf("Request error '%s'\n", errDo) return nil, errDo
return nil
} }
defer response.Body.Close() defer response.Body.Close()
@ -90,11 +97,10 @@ func getCharacterInfo(client *http.Client) *Character {
var m Character var m Character
errJSON := json.Unmarshal(contents, &m) errJSON := json.Unmarshal(contents, &m)
if errJSON != nil { if errJSON != nil {
fmt.Printf("JSON read error with '%s'\n", errJSON) return nil, errJSON
return nil
} }
return &m return &m, nil
} }
func getCharacterSkillQueue(client *http.Client, m *Character) { func getCharacterSkillQueue(client *http.Client, m *Character) {
@ -165,7 +171,7 @@ func getCharacterSkillQueue(client *http.Client, m *Character) {
continue continue
} }
fmt.Printf(" %s - level %d - %s to %s\n", fmt.Printf("% 35s - level %d - %s to %s\n",
name, name,
*skill.FinishedLevel, *skill.FinishedLevel,
time.Time(skill.StartDate).Format("_2 Jan 2006, 15:04"), time.Time(skill.StartDate).Format("_2 Jan 2006, 15:04"),