Public IP getter loop refactored

This commit is contained in:
Quentin McGaw
2020-12-28 01:51:55 +00:00
parent 91f5338db0
commit db886163c2
11 changed files with 279 additions and 135 deletions

View File

@@ -37,7 +37,7 @@ type Reader interface {
GetUID() (uid int, err error)
GetGID() (gid int, err error)
GetTimezone() (timezone string, err error)
GetIPStatusFilepath() (filepath models.Filepath, err error)
GetPublicIPFilepath() (filepath models.Filepath, err error)
// Firewall getters
GetFirewall() (enabled bool, err error)

View File

@@ -3,6 +3,7 @@ package params
import (
"time"
"github.com/qdm12/gluetun/internal/models"
libparams "github.com/qdm12/golibs/params"
)
@@ -15,3 +16,13 @@ func (r *reader) GetPublicIPPeriod() (period time.Duration, err error) {
}
return time.ParseDuration(s)
}
// GetPublicIPFilepath obtains the public IP filepath
// from the environment variable PUBLICIP_FILE with retro-compatible
// environment variable IP_STATUS_FILE.
func (r *reader) GetPublicIPFilepath() (filepath models.Filepath, err error) {
filepathStr, err := r.envParams.GetPath("PUBLICIP_FILE",
libparams.RetroKeys([]string{"IP_STATUS_FILE"}, r.onRetroActive),
libparams.Default("/tmp/gluetun/ip"), libparams.CaseSensitiveValue())
return models.Filepath(filepathStr), err
}

View File

@@ -1,7 +1,6 @@
package params
import (
"github.com/qdm12/gluetun/internal/models"
libparams "github.com/qdm12/golibs/params"
)
@@ -19,11 +18,3 @@ func (r *reader) GetGID() (gid int, err error) {
func (r *reader) GetTimezone() (timezone string, err error) {
return r.envParams.GetEnv("TZ")
}
// GetIPStatusFilepath obtains the IP status file path
// from the environment variable IP_STATUS_FILE.
func (r *reader) GetIPStatusFilepath() (filepath models.Filepath, err error) {
filepathStr, err := r.envParams.GetPath("IP_STATUS_FILE",
libparams.Default("/tmp/gluetun/ip"), libparams.CaseSensitiveValue())
return models.Filepath(filepathStr), err
}