|
@@ -0,0 +1,27 @@
|
|
|
|
|
+package dapr_api
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "github.com/go-resty/resty/v2"
|
|
|
|
|
+ "time"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+const (
|
|
|
|
|
+ healthUrlFormat = "http://localhost:%d/v1.0/healthz"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+func Health(daprPort int, timeout time.Duration) error {
|
|
|
|
|
+ healthUrl := fmt.Sprintf(healthUrlFormat, daprPort)
|
|
|
|
|
+
|
|
|
|
|
+ resp, err := resty.New().SetTimeout(timeout).R().Get(healthUrl)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if resp.IsError() {
|
|
|
|
|
+ return fmt.Errorf("Status %d: %s\n", resp.StatusCode(), resp.Body())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+
|
|
|
|
|
+}
|