1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-12-09 09:56:01 +02:00
imgproxy/healthcheck.go

48 lines
923 B
Go
Raw Normal View History

2020-02-04 13:48:33 +02:00
package main
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
2021-04-26 13:52:50 +02:00
2021-09-30 16:23:30 +02:00
"github.com/imgproxy/imgproxy/v3/config"
"github.com/imgproxy/imgproxy/v3/config/configurators"
2020-02-04 13:48:33 +02:00
)
2020-02-27 17:44:59 +02:00
func healthcheck() int {
2021-04-26 13:52:50 +02:00
network := config.Network
bind := config.Bind
pathprefix := config.PathPrefix
2020-02-04 13:48:33 +02:00
2021-04-26 13:52:50 +02:00
configurators.String(&network, "IMGPROXY_NETWORK")
configurators.String(&bind, "IMGPROXY_BIND")
configurators.String(&pathprefix, "IMGPROXY_PATH_PREFIX")
2020-02-04 13:48:33 +02:00
httpc := http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial(network, bind)
},
},
}
res, err := httpc.Get(fmt.Sprintf("http://imgproxy%s/health", pathprefix))
2020-02-04 13:48:33 +02:00
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
2020-02-27 17:44:59 +02:00
return 1
2020-02-04 13:48:33 +02:00
}
defer res.Body.Close()
msg, _ := ioutil.ReadAll(res.Body)
fmt.Fprintln(os.Stderr, string(msg))
if res.StatusCode != 200 {
2020-02-27 17:44:59 +02:00
return 1
2020-02-04 13:48:33 +02:00
}
2020-02-27 17:44:59 +02:00
return 0
2020-02-04 13:48:33 +02:00
}