health_check.go 922 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package cli // import "miniflux.app/v2/internal/cli"
  4. import (
  5. "fmt"
  6. "log/slog"
  7. "net/http"
  8. "time"
  9. "miniflux.app/v2/internal/config"
  10. )
  11. func doHealthCheck(healthCheckEndpoint string) {
  12. if healthCheckEndpoint == "auto" {
  13. healthCheckEndpoint = "http://" + config.Opts.ListenAddr()[0] + config.Opts.BasePath() + "/healthcheck"
  14. }
  15. slog.Debug("Executing health check request", slog.String("endpoint", healthCheckEndpoint))
  16. client := &http.Client{Timeout: 3 * time.Second}
  17. resp, err := client.Get(healthCheckEndpoint)
  18. if err != nil {
  19. printErrorAndExit(fmt.Errorf(`health check failure: %v`, err))
  20. }
  21. defer resp.Body.Close()
  22. if resp.StatusCode != 200 {
  23. printErrorAndExit(fmt.Errorf(`health check failed with status code %d`, resp.StatusCode))
  24. }
  25. slog.Debug(`Health check is passing`)
  26. }