forked from imgproxy/imgproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.go
47 lines (38 loc) · 913 Bytes
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"fmt"
"io"
"net"
"net/http"
"os"
"github.com/imgproxy/imgproxy/v3/config"
"github.com/imgproxy/imgproxy/v3/config/configurators"
)
func healthcheck() int {
network := config.Network
bind := config.Bind
pathprefix := config.PathPrefix
configurators.String(&network, "IMGPROXY_NETWORK")
configurators.String(&bind, "IMGPROXY_BIND")
configurators.URLPath(&pathprefix, "IMGPROXY_PATH_PREFIX")
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))
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return 1
}
defer res.Body.Close()
msg, _ := io.ReadAll(res.Body)
fmt.Fprintln(os.Stderr, string(msg))
if res.StatusCode != 200 {
return 1
}
return 0
}