Refactoring and cleanup of the code
This commit is contained in:
parent
673d28166d
commit
e3f0b4694e
1 changed files with 31 additions and 30 deletions
61
main.go
61
main.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -89,13 +90,16 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printCharacterInformation(client, m)
|
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
|
||||||
|
swaggerclient := ESI.New(transport, strfmt.Default)
|
||||||
|
|
||||||
|
printCharacterInformation(swaggerclient, m)
|
||||||
|
|
||||||
fmt.Printf("\n\nPlanetary interaction\n")
|
fmt.Printf("\n\nPlanetary interaction\n")
|
||||||
printCharacterPlanets(client, m)
|
printCharacterPlanets(swaggerclient, m)
|
||||||
|
|
||||||
fmt.Printf("\n\nSkill queue\n")
|
fmt.Printf("\n\nSkill queue\n")
|
||||||
printCharacterSkillQueue(client, m)
|
printCharacterSkillQueue(swaggerclient, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCharacterInfo(client *http.Client) (*Character, error) {
|
func getCharacterInfo(client *http.Client) (*Character, error) {
|
||||||
|
@ -112,22 +116,23 @@ func getCharacterInfo(client *http.Client) (*Character, error) {
|
||||||
var m Character
|
var m Character
|
||||||
errJSON := json.Unmarshal(contents, &m)
|
errJSON := json.Unmarshal(contents, &m)
|
||||||
if errJSON != nil {
|
if errJSON != nil {
|
||||||
|
log.Printf("Unmarshalling error: %s\n", errJSON)
|
||||||
return nil, errJSON
|
return nil, errJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.CharacterID == 0 || m.CharacterName == "" {
|
||||||
|
log.Printf("Invalid return value from verify call: %s", contents)
|
||||||
|
return nil, errors.New("Invalid token")
|
||||||
|
}
|
||||||
|
|
||||||
return &m, nil
|
return &m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterSkillQueue(client *http.Client, m *Character) {
|
func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) {
|
||||||
|
callParam := ESISkills.NewGetCharactersCharacterIDSkillqueueParams()
|
||||||
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
// create the transport
|
skillqueueresp, skillerr := swaggerclient.Skills.GetCharactersCharacterIDSkillqueue(callParam, nil)
|
||||||
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
|
|
||||||
|
|
||||||
// create the API client, with the transport
|
|
||||||
swaggerclient := ESI.New(transport, strfmt.Default)
|
|
||||||
|
|
||||||
charIDSkilqueue := ESISkills.NewGetCharactersCharacterIDSkillqueueParams().WithCharacterID(m.CharacterID)
|
|
||||||
skillqueueresp, skillerr := swaggerclient.Skills.GetCharactersCharacterIDSkillqueue(charIDSkilqueue, nil)
|
|
||||||
if skillerr != nil {
|
if skillerr != nil {
|
||||||
log.Fatalf("Error on GetCharactersCharacterIDSkillqueue\n%s\n", skillerr)
|
log.Fatalf("Error on GetCharactersCharacterIDSkillqueue\n%s\n", skillerr)
|
||||||
}
|
}
|
||||||
|
@ -168,18 +173,13 @@ func printCharacterSkillQueue(client *http.Client, m *Character) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterInformation(client *http.Client, m *Character) {
|
func printCharacterInformation(swaggerclient *ESI.App, m *Character) {
|
||||||
// create the transport
|
|
||||||
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
|
|
||||||
|
|
||||||
// create the API client, with the transport
|
|
||||||
swaggerclient := ESI.New(transport, strfmt.Default)
|
|
||||||
|
|
||||||
callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams()
|
callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
esiresponse, esierr := swaggerclient.Wallet.GetCharactersCharacterIDWallets(callParam, nil)
|
esiresponse, esierr := swaggerclient.Wallet.GetCharactersCharacterIDWallets(callParam, nil)
|
||||||
if esierr != nil {
|
if esierr != nil {
|
||||||
|
fmt.Println("Error while getting the wallet information")
|
||||||
log.Fatalf("Got error on GetCharactersCharacterIDWallets: %s", esierr)
|
log.Fatalf("Got error on GetCharactersCharacterIDWallets: %s", esierr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,16 +196,16 @@ func printCharacterInformation(client *http.Client, m *Character) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterPlanets(client *http.Client, m *Character) {
|
func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
|
|
||||||
// create the transport
|
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams()
|
||||||
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
// create the API client, with the transport
|
esiresponse, esierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanets(callParam, nil)
|
||||||
swaggerclient := ESI.New(transport, strfmt.Default)
|
if esierr != nil {
|
||||||
|
fmt.Println("Error while getting the planetary interaction information.")
|
||||||
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams().WithCharacterID(m.CharacterID)
|
log.Fatalf("Got error on GetCharactersCharacterIDPlanets: %s", esierr)
|
||||||
esiresponse, _ := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanets(callParam, nil)
|
}
|
||||||
|
|
||||||
planets := esiresponse.Payload
|
planets := esiresponse.Payload
|
||||||
|
|
||||||
|
@ -229,11 +229,12 @@ func printCharacterPlanets(client *http.Client, m *Character) {
|
||||||
solarSystemInfo.SolarSystemName,
|
solarSystemInfo.SolarSystemName,
|
||||||
*planet.PlanetType,
|
*planet.PlanetType,
|
||||||
*planet.UpgradeLevel, *planet.NumPins,
|
*planet.UpgradeLevel, *planet.NumPins,
|
||||||
planet.LastUpdate,
|
time.Time(*planet.LastUpdate).Format("_2 Jan 2006, 15:04"),
|
||||||
)
|
)
|
||||||
|
|
||||||
pesiresponse, pesierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanetsPlanetID(pcallParam, nil)
|
pesiresponse, pesierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanetsPlanetID(pcallParam, nil)
|
||||||
if pesierr != nil {
|
if pesierr != nil {
|
||||||
|
fmt.Println("Error while getting the planetary interaction information")
|
||||||
log.Fatalf("Error on CharactersCharacterIDPlanetsPlanetID: %s", pesierr)
|
log.Fatalf("Error on CharactersCharacterIDPlanetsPlanetID: %s", pesierr)
|
||||||
}
|
}
|
||||||
for _, pin := range pesiresponse.Payload.Pins {
|
for _, pin := range pesiresponse.Payload.Pins {
|
||||||
|
@ -511,11 +512,11 @@ func putCacheData(key string, value string) {
|
||||||
|
|
||||||
func getDatabaseToken() *oauth2.Token {
|
func getDatabaseToken() *oauth2.Token {
|
||||||
refreshToken := getCachedData("refreshToken")
|
refreshToken := getCachedData("refreshToken")
|
||||||
accessToken := getCachedData("accessToken")
|
//accessToken := getCachedData("accessToken")
|
||||||
|
|
||||||
token := new(oauth2.Token)
|
token := new(oauth2.Token)
|
||||||
token.RefreshToken = refreshToken
|
token.RefreshToken = refreshToken
|
||||||
token.AccessToken = accessToken
|
//token.AccessToken = accessToken
|
||||||
token.TokenType = "Bearer"
|
token.TokenType = "Bearer"
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
|
Reference in a new issue