Last change
on this file since 3 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:
527 bytes
|
Rev | Line | |
---|
[3] | 1 | package cmd
|
---|
| 2 |
|
---|
| 3 | import (
|
---|
| 4 | "fmt"
|
---|
| 5 | "io"
|
---|
| 6 | "log"
|
---|
| 7 | "net/http"
|
---|
| 8 |
|
---|
| 9 | "github.com/spf13/cobra"
|
---|
| 10 | )
|
---|
| 11 |
|
---|
| 12 | var moonCmd = &cobra.Command{
|
---|
| 13 | Use: "moon",
|
---|
| 14 | Short: "Check out the current moon phase",
|
---|
| 15 | Run: func(cmd *cobra.Command, args []string) {
|
---|
| 16 | query := "https://wttr.in/" + "moon" + "?" + 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", body)
|
---|
| 27 | },
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | func init() {
|
---|
| 31 | rootCmd.AddCommand(moonCmd)
|
---|
| 32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.