Using goroutines and channels between the different information functions
This commit is contained in:
parent
bb7be9b62a
commit
9244802e7e
1 changed files with 50 additions and 19 deletions
69
main.go
69
main.go
|
@ -120,13 +120,34 @@ func main() {
|
||||||
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
|
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
|
||||||
swaggerclient := ESI.New(transport, strfmt.Default)
|
swaggerclient := ESI.New(transport, strfmt.Default)
|
||||||
|
|
||||||
printCharacterInformation(swaggerclient, m)
|
charInfoChan := make(chan string)
|
||||||
|
cloneInfoChan := make(chan string)
|
||||||
|
planetInfoChan := make(chan string)
|
||||||
|
skillsInfoChan := make(chan string)
|
||||||
|
|
||||||
|
go printCharacterInformation(charInfoChan, swaggerclient, m)
|
||||||
|
go printClonesInformation(cloneInfoChan, swaggerclient, m)
|
||||||
|
go printCharacterPlanets(planetInfoChan, swaggerclient, m)
|
||||||
|
go printCharacterSkillQueue(skillsInfoChan, swaggerclient, m)
|
||||||
|
|
||||||
|
for msg := range charInfoChan {
|
||||||
|
fmt.Print(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\n\nClones\n")
|
||||||
|
for msg := range cloneInfoChan {
|
||||||
|
fmt.Print(msg)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("\n\nPlanetary interaction\n")
|
fmt.Printf("\n\nPlanetary interaction\n")
|
||||||
printCharacterPlanets(swaggerclient, m)
|
for msg := range planetInfoChan {
|
||||||
|
fmt.Print(msg)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("\n\nSkill queue\n")
|
fmt.Printf("\n\nSkill queue\n")
|
||||||
printCharacterSkillQueue(swaggerclient, m)
|
for msg := range skillsInfoChan {
|
||||||
|
fmt.Print(msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfigurationFile() error {
|
func readConfigurationFile() error {
|
||||||
|
@ -173,7 +194,7 @@ func getCharacterInfo(client *http.Client) (*Character, error) {
|
||||||
return &m, nil
|
return &m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) {
|
func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
||||||
callParam := ESISkills.NewGetCharactersCharacterIDSkillqueueParams()
|
callParam := ESISkills.NewGetCharactersCharacterIDSkillqueueParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
|
@ -216,7 +237,7 @@ func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) {
|
||||||
// The queue is only updated when the user logs in with the client
|
// The queue is only updated when the user logs in with the client
|
||||||
// we thus need to do the computations and filtering ourselves
|
// we thus need to do the computations and filtering ourselves
|
||||||
if finishDate.Before(time.Now()) {
|
if finishDate.Before(time.Now()) {
|
||||||
fmt.Printf("✔ %"+maxSkillFormat+"s %d\n",
|
outChan <- fmt.Sprintf("✔ %"+maxSkillFormat+"s %d\n",
|
||||||
name,
|
name,
|
||||||
*skill.FinishedLevel,
|
*skill.FinishedLevel,
|
||||||
)
|
)
|
||||||
|
@ -224,7 +245,7 @@ func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if startDate.Before(time.Now()) {
|
if startDate.Before(time.Now()) {
|
||||||
fmt.Printf("%s %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
outChan <- fmt.Sprintf("%s %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
||||||
aurora.Green("➠").Bold(),
|
aurora.Green("➠").Bold(),
|
||||||
name,
|
name,
|
||||||
*skill.FinishedLevel,
|
*skill.FinishedLevel,
|
||||||
|
@ -235,7 +256,7 @@ func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(" %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
outChan <- fmt.Sprintf(" %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
||||||
name,
|
name,
|
||||||
*skill.FinishedLevel,
|
*skill.FinishedLevel,
|
||||||
formatDuration(skillDuration, 2),
|
formatDuration(skillDuration, 2),
|
||||||
|
@ -243,6 +264,8 @@ func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) {
|
||||||
formatDuration(finishDuration, 3),
|
formatDuration(finishDuration, 3),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(outChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatDuration(duration time.Duration, daysLength int32) string {
|
func formatDuration(duration time.Duration, daysLength int32) string {
|
||||||
|
@ -253,7 +276,7 @@ func formatDuration(duration time.Duration, daysLength int32) string {
|
||||||
return fmt.Sprintf("%"+fmt.Sprintf("%d", daysLength)+"dd %02d:%02d", days, hours, minutes)
|
return fmt.Sprintf("%"+fmt.Sprintf("%d", daysLength)+"dd %02d:%02d", days, hours, minutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterInformation(swaggerclient *ESI.App, m *Character) {
|
func printCharacterInformation(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
||||||
callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams()
|
callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
|
@ -267,11 +290,11 @@ func printCharacterInformation(swaggerclient *ESI.App, m *Character) {
|
||||||
|
|
||||||
ac := accounting.Accounting{Symbol: "ISK ", Precision: 0, Thousand: "'"}
|
ac := accounting.Accounting{Symbol: "ISK ", Precision: 0, Thousand: "'"}
|
||||||
|
|
||||||
fmt.Printf("Name: %s\n", m.CharacterName)
|
outChan <- fmt.Sprintf("Name: %s\n", m.CharacterName)
|
||||||
|
|
||||||
for _, wallet := range wallets {
|
for _, wallet := range wallets {
|
||||||
if wallet.Balance > 0 {
|
if wallet.Balance > 0 {
|
||||||
fmt.Printf("Wallet: %s\n", ac.FormatMoney(wallet.Balance/100))
|
outChan <- fmt.Sprintf("Wallet: %s\n", ac.FormatMoney(wallet.Balance/100))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,11 +322,15 @@ func printCharacterInformation(swaggerclient *ESI.App, m *Character) {
|
||||||
stationName = universeNames[*position.StationID]
|
stationName = universeNames[*position.StationID]
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Currently in %s - %s\n",
|
outChan <- fmt.Sprintf("Currently in %s - %s\n",
|
||||||
universeNames[*position.SolarSystemID],
|
universeNames[*position.SolarSystemID],
|
||||||
stationName,
|
stationName,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
close(outChan)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printClonesInformation(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
||||||
cloCallParams := ESIClones.NewGetCharactersCharacterIDClonesParams()
|
cloCallParams := ESIClones.NewGetCharactersCharacterIDClonesParams()
|
||||||
cloCallParams.WithCharacterID(m.CharacterID)
|
cloCallParams.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
|
@ -315,11 +342,10 @@ func printCharacterInformation(swaggerclient *ESI.App, m *Character) {
|
||||||
|
|
||||||
clones := cloresponse.Payload.JumpClones
|
clones := cloresponse.Payload.JumpClones
|
||||||
|
|
||||||
fmt.Printf("\nClones: \n")
|
|
||||||
for _, clone := range clones {
|
for _, clone := range clones {
|
||||||
sInfo, _ := getStructureStationInfo(swaggerclient, clone.LocationType, clone.LocationID)
|
sInfo, _ := getStructureStationInfo(swaggerclient, clone.LocationType, clone.LocationID)
|
||||||
|
|
||||||
fmt.Printf(" %s, %s, %s\n ",
|
outChan <- fmt.Sprintf(" %s, %s, %s\n ",
|
||||||
sInfo.Name,
|
sInfo.Name,
|
||||||
sInfo.System.ConstellationName,
|
sInfo.System.ConstellationName,
|
||||||
sInfo.System.RegionName,
|
sInfo.System.RegionName,
|
||||||
|
@ -328,10 +354,13 @@ func printCharacterInformation(swaggerclient *ESI.App, m *Character) {
|
||||||
implantNames := getUniverseNames(swaggerclient, &clone.Implants)
|
implantNames := getUniverseNames(swaggerclient, &clone.Implants)
|
||||||
for _, implant := range clone.Implants {
|
for _, implant := range clone.Implants {
|
||||||
implantName := implantNames[implant]
|
implantName := implantNames[implant]
|
||||||
fmt.Printf(" %s, ", implantName)
|
outChan <- fmt.Sprintf(" %s, ", implantName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outChan <- "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(outChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
type structureInfo struct {
|
type structureInfo struct {
|
||||||
|
@ -410,7 +439,7 @@ func (s byPIPinType) Less(i, j int) bool {
|
||||||
return *a.PinID < *b.PinID
|
return *a.PinID < *b.PinID
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
||||||
|
|
||||||
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams()
|
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
@ -433,7 +462,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
|
|
||||||
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
||||||
|
|
||||||
fmt.Printf("Planet %s, %s, %s - Type %s, Lvl %d - Updated %s\n",
|
outChan <- fmt.Sprintf("Planet %s, %s, %s - Type %s, Lvl %d - Updated %s\n",
|
||||||
planetName.PlanetName,
|
planetName.PlanetName,
|
||||||
planetSystemInfo.ConstellationName,
|
planetSystemInfo.ConstellationName,
|
||||||
planetSystemInfo.RegionName,
|
planetSystemInfo.RegionName,
|
||||||
|
@ -471,7 +500,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
duration = time.Time(pin.ExpiryTime).Sub(now)
|
duration = time.Time(pin.ExpiryTime).Sub(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(" %s Extractor %4ds cycle, %s, %d per cycle, %s %s (%s)\n",
|
outChan <- fmt.Sprintf(" %s Extractor %4ds cycle, %s, %d per cycle, %s %s (%s)\n",
|
||||||
status,
|
status,
|
||||||
*pin.ExtractorDetails.CycleTime,
|
*pin.ExtractorDetails.CycleTime,
|
||||||
pinNames[*pin.ExtractorDetails.ProductTypeID],
|
pinNames[*pin.ExtractorDetails.ProductTypeID],
|
||||||
|
@ -486,9 +515,9 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
schematicInfo, serr := getSchematicsInformation(swaggerclient, pin.SchematicID)
|
schematicInfo, serr := getSchematicsInformation(swaggerclient, pin.SchematicID)
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
log.Printf("Error on getSchematicsInformation: %T, %s\n", serr, serr)
|
log.Printf("Error on getSchematicsInformation: %T, %s\n", serr, serr)
|
||||||
fmt.Printf(" ✔ Factory ????? cycle, ?????\n")
|
outChan <- fmt.Sprintf(" ✔ Factory ????? cycle, ?????\n")
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" ✔ Factory %4ds cycle, %s\n",
|
outChan <- fmt.Sprintf(" ✔ Factory %4ds cycle, %s\n",
|
||||||
schematicInfo.CycleTime,
|
schematicInfo.CycleTime,
|
||||||
schematicInfo.SchematicName,
|
schematicInfo.SchematicName,
|
||||||
)
|
)
|
||||||
|
@ -496,6 +525,8 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(outChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string {
|
func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string {
|
||||||
|
|
Reference in a new issue