From a520941a9653fc9ce8fc265a1c9e462bf43ad024 Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Date: Wed, 19 Feb 2025 17:37:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/openstatus/main.go | 4 ++-- internal/config/config.go | 11 +++++++++-- internal/run/run.go | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/openstatus/main.go b/cmd/openstatus/main.go index 11a9858..2c606ad 100644 --- a/cmd/openstatus/main.go +++ b/cmd/openstatus/main.go @@ -13,9 +13,9 @@ import ( func main() { app := &cli.Command{ - Name: "OpenStatus", + Name: "openstatus", Usage: "This is OpenStatus Command Line Interface", - Version: "v0.0.2", + Version: "v0.0.3", Commands: []*cli.Command{ monitors.MonitorsCmd(), run.RunCmd(), diff --git a/internal/config/config.go b/internal/config/config.go index a0689d0..9be0f46 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -18,11 +18,18 @@ type Config struct { } func ReadConfig(path string) (*Config, error) { - k.Load(file.Provider(path), yaml.Parser()) + + file := file.Provider(path) + + err:= k.Load(file, yaml.Parser()) + + if err != nil { + return nil, err + } var out Config - err := k.Unmarshal("", &out) + err = k.Unmarshal("", &out) if err != nil { return nil, err } diff --git a/internal/run/run.go b/internal/run/run.go index 067fc6c..de39e9c 100644 --- a/internal/run/run.go +++ b/internal/run/run.go @@ -3,10 +3,14 @@ package run import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" + "os" + "strings" "sync" + "time" "github.com/fatih/color" "github.com/openstatusHQ/cli/internal/config" @@ -23,7 +27,11 @@ func MonitorTrigger(httpClient *http.Client, apiKey string, monitorId string) er url := fmt.Sprintf("https://api.openstatus.dev/v1/monitor/%s/run", monitorId) - req, err := http.NewRequest("POST", url, nil) + httpClient.Timeout = 2 * time.Minute + + payload := strings.NewReader("{}") + + req, err := http.NewRequest("POST", url, payload) if err != nil { return err } @@ -113,6 +121,12 @@ func RunCmd() *cli.Command { Action: func(ctx context.Context, cmd *cli.Command) error { path := cmd.String("config") + if path != "" { + if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) { + return cli.Exit("Config does not exist", 1) + } + } + conf, err := config.ReadConfig(path) if err != nil { return err @@ -124,6 +138,7 @@ func RunCmd() *cli.Command { var wg sync.WaitGroup + for _, id := range conf.Tests.Ids { wg.Add(1) go func(id int) { -- knotmirror 0.0.1