- Better settings tree structure logged using `qdm12/gotree` - Read settings from environment variables, then files, then secret files - Settings methods to default them, merge them and override them - `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else. - `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
43 lines
916 B
Go
43 lines
916 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/qdm12/gluetun/internal/configuration/sources"
|
|
"github.com/qdm12/gluetun/internal/healthcheck"
|
|
)
|
|
|
|
type HealthChecker interface {
|
|
HealthCheck(ctx context.Context, source sources.Source, warner Warner) error
|
|
}
|
|
|
|
func (c *CLI) HealthCheck(ctx context.Context, source sources.Source, warner Warner) error {
|
|
// Extract the health server port from the configuration.
|
|
config, err := source.ReadHealth()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = config.Validate()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, port, err := net.SplitHostPort(config.ServerAddress)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
const timeout = 10 * time.Second
|
|
httpClient := &http.Client{Timeout: timeout}
|
|
client := healthcheck.NewClient(httpClient)
|
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
|
defer cancel()
|
|
|
|
url := "http://127.0.0.1:" + port
|
|
return client.Check(ctx, url)
|
|
}
|