Print methods again return a string and the chan is created in the goroutine
This commit is contained in:
parent
b1113dff25
commit
f51c48d68b
1 changed files with 47 additions and 25 deletions
72
main.go
72
main.go
|
@ -122,10 +122,25 @@ func main() {
|
||||||
planetInfoChan := make(chan string)
|
planetInfoChan := make(chan string)
|
||||||
skillsInfoChan := make(chan string)
|
skillsInfoChan := make(chan string)
|
||||||
|
|
||||||
go printCharacterInformation(charInfoChan, swaggerclient, m)
|
go func() {
|
||||||
go printClonesInformation(cloneInfoChan, swaggerclient, m)
|
charInfoChan <- printCharacterInformation(swaggerclient, m)
|
||||||
go printCharacterPlanets(planetInfoChan, swaggerclient, m)
|
close(charInfoChan)
|
||||||
go printCharacterSkillQueue(skillsInfoChan, swaggerclient, m)
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
cloneInfoChan <- printClonesInformation(swaggerclient, m)
|
||||||
|
close(cloneInfoChan)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
planetInfoChan <- printCharacterPlanets(swaggerclient, m)
|
||||||
|
close(planetInfoChan)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
skillsInfoChan <- printCharacterSkillQueue(swaggerclient, m)
|
||||||
|
close(skillsInfoChan)
|
||||||
|
}()
|
||||||
|
|
||||||
for msg := range charInfoChan {
|
for msg := range charInfoChan {
|
||||||
fmt.Print(msg)
|
fmt.Print(msg)
|
||||||
|
@ -195,7 +210,7 @@ func getCharacterInfo(client *http.Client) (*Character, error) {
|
||||||
return &m, nil
|
return &m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) string {
|
||||||
callParam := ESISkills.NewGetCharactersCharacterIDSkillqueueParams()
|
callParam := ESISkills.NewGetCharactersCharacterIDSkillqueueParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
|
@ -214,6 +229,8 @@ func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Ch
|
||||||
}
|
}
|
||||||
skillNames := getUniverseNames(swaggerclient, &snIds)
|
skillNames := getUniverseNames(swaggerclient, &snIds)
|
||||||
|
|
||||||
|
var content string
|
||||||
|
|
||||||
maxSkillLength := 0
|
maxSkillLength := 0
|
||||||
for _, skill := range skillqueue {
|
for _, skill := range skillqueue {
|
||||||
name := skillNames[*skill.SkillID]
|
name := skillNames[*skill.SkillID]
|
||||||
|
@ -238,7 +255,7 @@ func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Ch
|
||||||
// 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()) {
|
||||||
outChan <- fmt.Sprintf("✔ %"+maxSkillFormat+"s %d\n",
|
content = content + fmt.Sprintf("✔ %"+maxSkillFormat+"s %d\n",
|
||||||
name,
|
name,
|
||||||
*skill.FinishedLevel,
|
*skill.FinishedLevel,
|
||||||
)
|
)
|
||||||
|
@ -246,7 +263,7 @@ func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Ch
|
||||||
}
|
}
|
||||||
|
|
||||||
if startDate.Before(time.Now()) {
|
if startDate.Before(time.Now()) {
|
||||||
outChan <- fmt.Sprintf("%s %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
content = content + fmt.Sprintf("%s %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
||||||
aurora.Green("➠").Bold(),
|
aurora.Green("➠").Bold(),
|
||||||
name,
|
name,
|
||||||
*skill.FinishedLevel,
|
*skill.FinishedLevel,
|
||||||
|
@ -257,7 +274,7 @@ func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Ch
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
outChan <- fmt.Sprintf(" %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
content = content + fmt.Sprintf(" %"+maxSkillFormat+"s %d, %s - ends on %s (%s)\n",
|
||||||
name,
|
name,
|
||||||
*skill.FinishedLevel,
|
*skill.FinishedLevel,
|
||||||
formatDuration(skillDuration, 2),
|
formatDuration(skillDuration, 2),
|
||||||
|
@ -266,7 +283,7 @@ func printCharacterSkillQueue(outChan chan string, swaggerclient *ESI.App, m *Ch
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
close(outChan)
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatDuration(duration time.Duration, daysLength int32) string {
|
func formatDuration(duration time.Duration, daysLength int32) string {
|
||||||
|
@ -277,7 +294,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(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
func printCharacterInformation(swaggerclient *ESI.App, m *Character) string {
|
||||||
callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams()
|
callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
|
@ -291,11 +308,12 @@ func printCharacterInformation(outChan chan string, swaggerclient *ESI.App, m *C
|
||||||
|
|
||||||
ac := accounting.Accounting{Symbol: "ISK ", Precision: 0, Thousand: "'"}
|
ac := accounting.Accounting{Symbol: "ISK ", Precision: 0, Thousand: "'"}
|
||||||
|
|
||||||
outChan <- fmt.Sprintf("Name: %s\n", m.CharacterName)
|
var content string
|
||||||
|
content = content + fmt.Sprintf("Name: %s\n", m.CharacterName)
|
||||||
|
|
||||||
for _, wallet := range wallets {
|
for _, wallet := range wallets {
|
||||||
if wallet.Balance > 0 {
|
if wallet.Balance > 0 {
|
||||||
outChan <- fmt.Sprintf("Wallet: %s\n", ac.FormatMoney(wallet.Balance/100))
|
content = content + fmt.Sprintf("Wallet: %s\n", ac.FormatMoney(wallet.Balance/100))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,15 +348,15 @@ func printCharacterInformation(outChan chan string, swaggerclient *ESI.App, m *C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outChan <- fmt.Sprintf("Currently in %s - %s\n",
|
content = content + fmt.Sprintf("Currently in %s - %s\n",
|
||||||
universeNames[*position.SolarSystemID],
|
universeNames[*position.SolarSystemID],
|
||||||
stationName,
|
stationName,
|
||||||
)
|
)
|
||||||
|
|
||||||
close(outChan)
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
func printClonesInformation(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
func printClonesInformation(swaggerclient *ESI.App, m *Character) string {
|
||||||
cloCallParams := ESIClones.NewGetCharactersCharacterIDClonesParams()
|
cloCallParams := ESIClones.NewGetCharactersCharacterIDClonesParams()
|
||||||
cloCallParams.WithCharacterID(m.CharacterID)
|
cloCallParams.WithCharacterID(m.CharacterID)
|
||||||
|
|
||||||
|
@ -348,12 +366,14 @@ func printClonesInformation(outChan chan string, swaggerclient *ESI.App, m *Char
|
||||||
log.Fatalf("Got error on GetCharactersCharacterIDClones: %s", cloerr)
|
log.Fatalf("Got error on GetCharactersCharacterIDClones: %s", cloerr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var content string
|
||||||
|
|
||||||
clones := cloresponse.Payload.JumpClones
|
clones := cloresponse.Payload.JumpClones
|
||||||
|
|
||||||
for _, clone := range clones {
|
for _, clone := range clones {
|
||||||
sInfo, _ := getStructureStationInfo(swaggerclient, clone.LocationType, clone.LocationID)
|
sInfo, _ := getStructureStationInfo(swaggerclient, clone.LocationType, clone.LocationID)
|
||||||
|
|
||||||
outChan <- fmt.Sprintf(" %s, %s, %s\n ",
|
content = content + fmt.Sprintf(" %s, %s, %s\n ",
|
||||||
sInfo.Name,
|
sInfo.Name,
|
||||||
sInfo.System.ConstellationName,
|
sInfo.System.ConstellationName,
|
||||||
sInfo.System.RegionName,
|
sInfo.System.RegionName,
|
||||||
|
@ -362,13 +382,13 @@ func printClonesInformation(outChan chan string, swaggerclient *ESI.App, m *Char
|
||||||
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]
|
||||||
outChan <- fmt.Sprintf(" %s, ", implantName)
|
content = content + fmt.Sprintf(" %s, ", implantName)
|
||||||
}
|
}
|
||||||
|
|
||||||
outChan <- "\n"
|
content = content + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
close(outChan)
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
type structureInfo struct {
|
type structureInfo struct {
|
||||||
|
@ -472,7 +492,7 @@ func (s byPIPinType) Less(i, j int) bool {
|
||||||
return *a.PinID < *b.PinID
|
return *a.PinID < *b.PinID
|
||||||
}
|
}
|
||||||
|
|
||||||
func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Character) {
|
func printCharacterPlanets(swaggerclient *ESI.App, m *Character) string {
|
||||||
|
|
||||||
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams()
|
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams()
|
||||||
callParam.WithCharacterID(m.CharacterID)
|
callParam.WithCharacterID(m.CharacterID)
|
||||||
|
@ -485,6 +505,8 @@ func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Chara
|
||||||
|
|
||||||
planets := esiresponse.Payload
|
planets := esiresponse.Payload
|
||||||
|
|
||||||
|
var content string
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
for _, planet := range planets {
|
for _, planet := range planets {
|
||||||
|
@ -495,7 +517,7 @@ func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Chara
|
||||||
|
|
||||||
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
||||||
|
|
||||||
outChan <- fmt.Sprintf("Planet %s, %s, %s - Type %s, Lvl %d - Updated %s\n",
|
content = content + 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,
|
||||||
|
@ -533,7 +555,7 @@ func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Chara
|
||||||
duration = time.Time(pin.ExpiryTime).Sub(now)
|
duration = time.Time(pin.ExpiryTime).Sub(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
outChan <- fmt.Sprintf(" %s Extractor %4ds cycle, %s, %d per cycle, %s %s (%s)\n",
|
content = content + 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],
|
||||||
|
@ -548,9 +570,9 @@ func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Chara
|
||||||
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)
|
||||||
outChan <- fmt.Sprintf(" ✔ Factory ????? cycle, ?????\n")
|
content = content + fmt.Sprintf(" ✔ Factory ????? cycle, ?????\n")
|
||||||
} else {
|
} else {
|
||||||
outChan <- fmt.Sprintf(" ✔ Factory %4ds cycle, %s\n",
|
content = content + fmt.Sprintf(" ✔ Factory %4ds cycle, %s\n",
|
||||||
schematicInfo.CycleTime,
|
schematicInfo.CycleTime,
|
||||||
schematicInfo.SchematicName,
|
schematicInfo.SchematicName,
|
||||||
)
|
)
|
||||||
|
@ -559,7 +581,7 @@ func printCharacterPlanets(outChan chan string, swaggerclient *ESI.App, m *Chara
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(outChan)
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
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