dapr_api.go 463 B

123456789101112131415161718192021222324252627
  1. package dapr_api
  2. import (
  3. "fmt"
  4. "github.com/go-resty/resty/v2"
  5. "time"
  6. )
  7. const (
  8. healthUrlFormat = "http://localhost:%d/v1.0/healthz"
  9. )
  10. func Health(daprPort int, timeout time.Duration) error {
  11. healthUrl := fmt.Sprintf(healthUrlFormat, daprPort)
  12. resp, err := resty.New().SetTimeout(timeout).R().Get(healthUrl)
  13. if err != nil {
  14. return err
  15. }
  16. if resp.IsError() {
  17. return fmt.Errorf("Status %d: %s\n", resp.StatusCode(), resp.Body())
  18. }
  19. return nil
  20. }