// $TheSupernovaDuo: yuuka,v master 2023/5/29 17:54:15 yakumo_izuru Exp $ package main import ( "fmt" "io" "log" "net/http" "os" ) var ( format = "?AT" url = "https://wttr.in" ) func main() { if len(os.Args) == 1 { PrintUsage() } cmd := os.Args[1] switch cmd { case "forecast": ShowForecast() case "moon": ShowMoonPhases() } } func PrintUsage() { fmt.Println("Yuuka is a wttr.in client") fmt.Printf("\tforecast\tShow the current weather report according to your region\n") fmt.Printf("\tmoon\tShow the current phase of the Moon\n") } func ShowForecast() { query := url + format resp, err := http.Get(query) sanityCheck(err) defer resp.Body.Close() body, err := io.ReadAll(resp.Body) sanityCheck(err) fmt.Printf("%s", body) } func ShowMoonPhases() { query := url + "/Moon" + format resp, err := http.Get(query) sanityCheck(err) defer resp.Body.Close() body, err := io.ReadAll(resp.Body) sanityCheck(err) fmt.Printf("%s\n", body) } func sanityCheck(err error) { if err != nil { log.Fatal(err) } }