go-challenge/main.go

41 lines
873 B
Go
Raw Normal View History

2022-10-21 12:02:03 -05:00
package main
import (
2022-10-22 01:06:30 -05:00
"fmt"
2022-10-21 12:02:03 -05:00
log "github.com/sirupsen/logrus"
"os"
)
func init() {
2022-10-22 01:06:30 -05:00
// log.SetFormatter(&log.JSONFormatter{})
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, DisableColors: false, ForceColors: true})
2022-10-21 12:02:03 -05:00
log.SetOutput(os.Stdout)
desiredLogLevel := os.Getenv("LOG_LEVEL")
level, err := log.ParseLevel(desiredLogLevel)
if err != nil {
2022-10-22 01:06:30 -05:00
log.Debugf("Failed to parse log level: %s", desiredLogLevel)
log.SetLevel(log.WarnLevel)
2022-10-21 12:02:03 -05:00
} else {
log.SetLevel(level)
}
}
func main() {
2022-10-22 01:06:30 -05:00
starships, err := AllStarships()
if err != nil {
log.Errorf("Error loading Starships: %+v", err)
os.Exit(1)
}
data := GetStarshipsPilots(starships)
for starship, pilots := range data {
if len(pilots) <= 0 {
continue
}
fmt.Println(starship.Name)
for _, pilot := range pilots {
if pilot != nil {
fmt.Println(" " + pilot.Name)
}
}
}
2022-10-21 12:02:03 -05:00
}