1
0

healthcheck.go 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "net"
  7. "net/http"
  8. "os"
  9. "github.com/imgproxy/imgproxy/v3/config"
  10. "github.com/imgproxy/imgproxy/v3/config/configurators"
  11. )
  12. func healthcheck() int {
  13. network := config.Network
  14. bind := config.Bind
  15. pathprefix := config.PathPrefix
  16. configurators.String(&network, "IMGPROXY_NETWORK")
  17. configurators.String(&bind, "IMGPROXY_BIND")
  18. configurators.URLPath(&pathprefix, "IMGPROXY_PATH_PREFIX")
  19. httpc := http.Client{
  20. Transport: &http.Transport{
  21. DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
  22. return net.Dial(network, bind)
  23. },
  24. },
  25. }
  26. res, err := httpc.Get(fmt.Sprintf("http://imgproxy%s/health", pathprefix))
  27. if err != nil {
  28. fmt.Fprintln(os.Stderr, err.Error())
  29. return 1
  30. }
  31. defer res.Body.Close()
  32. msg, _ := io.ReadAll(res.Body)
  33. fmt.Fprintln(os.Stderr, string(msg))
  34. if res.StatusCode != 200 {
  35. return 1
  36. }
  37. return 0
  38. }