45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package env
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
|
)
|
|
|
|
func (r *Reader) ReadHealth() (health settings.Health, err error) {
|
|
health.ServerAddress = getCleanedEnv("HEALTH_SERVER_ADDRESS")
|
|
_, health.TargetAddress = r.getEnvWithRetro("HEALTH_TARGET_ADDRESS", "HEALTH_ADDRESS_TO_PING")
|
|
|
|
health.VPN.Initial, err = r.readDurationWithRetro(
|
|
"HEALTH_VPN_DURATION_INITIAL",
|
|
"HEALTH_OPENVPN_DURATION_INITIAL")
|
|
if err != nil {
|
|
return health, err
|
|
}
|
|
|
|
health.VPN.Addition, err = r.readDurationWithRetro(
|
|
"HEALTH_VPN_DURATION_ADDITION",
|
|
"HEALTH_OPENVPN_DURATION_ADDITION")
|
|
if err != nil {
|
|
return health, err
|
|
}
|
|
|
|
return health, nil
|
|
}
|
|
|
|
func (r *Reader) readDurationWithRetro(envKey, retroEnvKey string) (d *time.Duration, err error) {
|
|
envKey, s := r.getEnvWithRetro(envKey, retroEnvKey)
|
|
if s == "" {
|
|
return nil, nil //nolint:nilnil
|
|
}
|
|
|
|
d = new(time.Duration)
|
|
*d, err = time.ParseDuration(s)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("environment variable %s: %w", envKey, err)
|
|
}
|
|
|
|
return d, nil
|
|
}
|