master
1package shouldideploytoday
2
3import (
4 "context"
5 "fmt"
6 "time"
7
8 "github.com/carlmjohnson/requests"
9 "github.com/kahnwong/swissknife/configs/color"
10)
11
12type ShouldIDeploy struct {
13 Timezone string `json:"timezone"`
14 Date time.Time `json:"date"`
15 ShouldIDeploy bool `json:"shouldideploy"`
16 Message string `json:"message"`
17}
18
19func getResponse() (ShouldIDeploy, error) {
20 url := "https://shouldideploy.today"
21
22 var response ShouldIDeploy
23 err := requests.
24 URL(url).
25 Path("api").
26 Param("tz", "UTC").
27 Param("date", time.Now().UTC().Format("2006-01-02T15:04:05.000Z")).
28 ToJSON(&response).
29 Fetch(context.Background())
30
31 if err != nil {
32 return ShouldIDeploy{}, fmt.Errorf("error calling ShouldIDeploy API: %w", err)
33 }
34
35 return response, nil
36}
37
38func ShouldIDeployToday() error {
39 response, err := getResponse()
40 if err != nil {
41 return err
42 }
43
44 if response.ShouldIDeploy {
45 fmt.Printf("%s\n", color.Green(response.Message))
46 } else if !response.ShouldIDeploy {
47 fmt.Printf("%s\n", color.Red(response.Message))
48 }
49 return nil
50}