source: code/trunk/cmd/forecast.go

Last change on this file was 3, checked in by Izuru Yakumo, 5 weeks ago

You humans are so full of yourselves. If you want to live a long life, then you should be a little more quiet.

File size: 560 bytes
Line 
1package cmd
2
3import (
4 "fmt"
5 "io"
6 "log"
7 "net/http"
8
9 "github.com/spf13/cobra"
10)
11
12var forecastCmd = &cobra.Command{
13 Use: "forecast",
14 Short: "Display the weather forecast for a specific location",
15 Run: func(cmd *cobra.Command, args []string) {
16 query := "https://wttr.in" + region + "?" + format
17 resp, err := http.Get(query)
18 if err != nil {
19 log.Fatal(err)
20 }
21 defer resp.Body.Close()
22 body, err := io.ReadAll(resp.Body)
23 if err != nil {
24 log.Fatal(err)
25 }
26 fmt.Printf("%s\n", body)
27 },
28}
29
30func init() {
31 rootCmd.AddCommand(forecastCmd)
32}
Note: See TracBrowser for help on using the repository browser.