chore(all): format code using gofumpt

This commit is contained in:
Quentin McGaw
2024-10-20 13:12:33 +00:00
parent 4c7c794494
commit 05d566c807
104 changed files with 308 additions and 178 deletions

View File

@@ -97,6 +97,7 @@
}
},
"gopls": {
"formatting.gofumpt": true,
"usePlaceholders": false,
"staticcheck": true,
"vulncheck": "Imports"

View File

@@ -47,6 +47,7 @@ linters:
- gocritic
- gocyclo
- godot
- gofumpt
- goheader
- goimports
- gomoddirectives

View File

@@ -99,7 +99,8 @@ func main() {
}
func _main(ctx context.Context, reader *reader.Reader, args []string, logger log.LoggerInterface,
buildInfo models.BuildInformation, timeNow func() time.Time) (err error) {
buildInfo models.BuildInformation, timeNow func() time.Time,
) (err error) {
if len(args) > 1 {
switch args[1] {
case "version", "-version", "--version":
@@ -290,7 +291,8 @@ func printSplash(buildInfo models.BuildInformation) {
}
func readConfig(reader *reader.Reader, logger log.LoggerInterface) (
config config.Config, err error) {
config config.Config, err error,
) {
err = config.Read(reader, logger)
if err != nil {
return config, fmt.Errorf("reading settings: %w", err)
@@ -320,7 +322,8 @@ func logProvidersCount(providersCount int, logger log.LeveledLogger) {
func readRecords(providers []provider.Provider, persistentDB *persistence.Database,
logger log.LoggerInterface, shoutrrrClient *shoutrrr.Client) (
records []recordslib.Record, err error) {
records []recordslib.Record, err error,
) {
records = make([]recordslib.Record, len(providers))
for i, provider := range providers {
logger.Info("Reading history from database: domain " +
@@ -338,7 +341,8 @@ func readRecords(providers []provider.Provider, persistentDB *persistence.Databa
}
func exitHealthchecksio(hioClient *healthchecksio.Client,
logger log.LoggerInterface, state healthchecksio.State) {
logger log.LoggerInterface, state healthchecksio.State,
) {
const timeout = 3 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
@@ -351,7 +355,8 @@ func exitHealthchecksio(hioClient *healthchecksio.Client,
//nolint:ireturn
func createHealthServer(db health.AllSelecter, resolver health.LookupIPer,
logger log.LoggerInterface, serverAddress string) (
healthServer goservices.Service, err error) {
healthServer goservices.Service, err error,
) {
if serverAddress == "" {
return noop.New("healthcheck server"), nil
}
@@ -364,7 +369,8 @@ func createHealthServer(db health.AllSelecter, resolver health.LookupIPer,
func createServer(ctx context.Context, config config.Server,
logger log.LoggerInterface, db server.Database,
updaterService server.UpdateForcer) (
service goservices.Service, err error) {
service goservices.Service, err error,
) {
if !*config.Enabled {
return noop.New("server"), nil
}

View File

@@ -20,7 +20,8 @@ type Service struct {
}
func New(backupPeriod time.Duration,
dataDir, outputDir string, logger Logger) *Service {
dataDir, outputDir string, logger Logger,
) *Service {
return &Service{
logger: logger,
backupPeriod: backupPeriod,
@@ -56,7 +57,8 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, startErr er
func run(ready chan<- struct{}, runError chan<- error, stopCh <-chan struct{},
done chan<- struct{}, outputDir, dataDir string, backupPeriod time.Duration,
logger Logger) {
logger Logger,
) {
defer close(done)
if backupPeriod == 0 {

View File

@@ -111,7 +111,8 @@ func (p *PubIP) ToHTTPOptions() (options []http.Option) {
}
func stringsToHTTPProviders(providers []string, ipVersion ipversion.IPVersion) (
updatedProviders []http.Provider) {
updatedProviders []http.Provider,
) {
updatedProvidersSet := make(map[string]struct{}, len(providers))
for _, provider := range providers {
if provider != all {
@@ -158,9 +159,7 @@ func (p *PubIP) ToDNSPOptions() (options []dns.Option) {
}
}
var (
ErrNoPublicIPDNSProvider = errors.New("no public IP DNS provider specified")
)
var ErrNoPublicIPDNSProvider = errors.New("no public IP DNS provider specified")
func (p PubIP) validateDNSProviders() (err error) {
if len(p.DNSProviders) == 0 {
@@ -194,7 +193,8 @@ var (
)
func validateHTTPIPProviders(providerStrings []string,
version ipversion.IPVersion) (err error) {
version ipversion.IPVersion,
) (err error) {
if len(providerStrings) == 0 {
return fmt.Errorf("%w", ErrNoPublicIPHTTPProvider)
}

View File

@@ -80,7 +80,8 @@ func (c Config) toLinesNode() *gotree.Node {
}
func (c *Config) Read(reader *reader.Reader,
warner Warner) (err error) {
warner Warner,
) (err error) {
err = c.Client.read(reader)
if err != nil {
return fmt.Errorf("reading client settings: %w", err)

View File

@@ -7,9 +7,7 @@ import (
"net/http"
)
var (
ErrHTTPStatusCodeNotOK = errors.New("status code is not OK")
)
var ErrHTTPStatusCodeNotOK = errors.New("status code is not OK")
func CheckHTTP(ctx context.Context, client *http.Client) (err error) {
const url = "https://github.com"

View File

@@ -7,7 +7,8 @@ import (
)
func NewServer(address string, logger Logger, healthcheck func(context.Context) error) (
server *httpserver.Server, err error) {
server *httpserver.Server, err error,
) {
name := "health"
return httpserver.New(httpserver.Settings{
Handler: newHandler(healthcheck),

View File

@@ -23,9 +23,7 @@ type Client struct {
uuid string
}
var (
ErrStatusCode = errors.New("bad status code")
)
var ErrStatusCode = errors.New("bad status code")
type State string

View File

@@ -35,7 +35,8 @@ type commonSettings struct {
// first trying from the environment variable CONFIG and then from
// the file config.json.
func (r *Reader) JSONProviders(filePath string) (
providers []provider.Provider, warnings []string, err error) {
providers []provider.Provider, warnings []string, err error,
) {
providers, warnings, err = r.getProvidersFromEnv(filePath)
if providers != nil || warnings != nil || err != nil {
return providers, warnings, err
@@ -47,7 +48,8 @@ var errWriteConfigToFile = errors.New("cannot write configuration to file")
// getProvidersFromFile obtain the update settings from config.json.
func (r *Reader) getProvidersFromFile(filePath string) (
providers []provider.Provider, warnings []string, err error) {
providers []provider.Provider, warnings []string, err error,
) {
r.logger.Info("reading JSON config from file " + filePath)
bytes, err := r.readFile(filePath)
if err != nil {
@@ -72,7 +74,8 @@ func (r *Reader) getProvidersFromFile(filePath string) (
// getProvidersFromEnv obtain the update settings from the environment variable CONFIG.
// If the settings are valid, they are written to the filePath.
func (r *Reader) getProvidersFromEnv(filePath string) (
providers []provider.Provider, warnings []string, err error) {
providers []provider.Provider, warnings []string, err error,
) {
s := os.Getenv("CONFIG")
if s == "" {
return nil, nil, nil
@@ -107,7 +110,8 @@ var (
)
func extractAllSettings(jsonBytes []byte) (
allProviders []provider.Provider, warnings []string, err error) {
allProviders []provider.Provider, warnings []string, err error,
) {
config := struct {
CommonSettings []commonSettings `json:"settings"`
}{}
@@ -141,13 +145,12 @@ func extractAllSettings(jsonBytes []byte) (
return allProviders, warnings, nil
}
var (
ErrProviderNoLongerSupported = errors.New("provider no longer supported")
)
var ErrProviderNoLongerSupported = errors.New("provider no longer supported")
func makeSettingsFromObject(common commonSettings, rawSettings json.RawMessage,
retroGlobalIPv6Suffix netip.Prefix) (
providers []provider.Provider, warnings []string, err error) {
providers []provider.Provider, warnings []string, err error,
) {
if common.Provider == "google" {
return nil, nil, fmt.Errorf("%w: %s", ErrProviderNoLongerSupported, common.Provider)
}
@@ -214,12 +217,11 @@ func makeSettingsFromObject(common commonSettings, rawSettings json.RawMessage,
return providers, warnings, nil
}
var (
ErrMultipleDomainsSpecified = errors.New("multiple domains specified")
)
var ErrMultipleDomainsSpecified = errors.New("multiple domains specified")
func extractFromDomainField(domainField string) (domainRegistered string,
owners []string, err error) {
owners []string, err error,
) {
domains := strings.Split(domainField, ",")
owners = make([]string, len(domains))
for i, domain := range domains {

View File

@@ -18,9 +18,7 @@ func getRetroIPv6Suffix() (suffix netip.Prefix, err error) {
return makeIPv6Suffix(prefixBitsString)
}
var (
ErrIPv6PrefixFormat = errors.New("IPv6 prefix format is incorrect")
)
var ErrIPv6PrefixFormat = errors.New("IPv6 prefix format is incorrect")
func makeIPv6Suffix(prefixBitsString string) (suffix netip.Prefix, err error) {
prefixBitsString = strings.TrimPrefix(prefixBitsString, "/")

View File

@@ -42,7 +42,8 @@ func (db *Database) StoreNewIP(domain, owner string, ip netip.Addr, t time.Time)
// GetEvents gets all the IP addresses history for a certain domain, owner and
// IP version, in the order from oldest to newest.
func (db *Database) GetEvents(domain, owner string,
ipVersion ipversion.IPVersion) (events []models.HistoryEvent, err error) {
ipVersion ipversion.IPVersion,
) (events []models.HistoryEvent, err error) {
db.mutex.RLock()
defer db.mutex.RUnlock()
for _, record := range db.data.Records {

View File

@@ -78,7 +78,8 @@ var ErrProviderUnknown = errors.New("unknown provider")
//nolint:gocyclo
func New(providerName models.Provider, data json.RawMessage, domain, owner string, //nolint:ireturn
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (provider Provider, err error) {
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix,
) (provider Provider, err error) {
switch providerName {
case constants.Aliyun:
return aliyun.New(data, domain, owner, ipVersion, ipv6Suffix)

View File

@@ -14,7 +14,8 @@ import (
)
func (p *Provider) createRecord(ctx context.Context,
client *http.Client, ip netip.Addr) (recordID string, err error) {
client *http.Client, ip netip.Addr,
) (recordID string, err error) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -13,7 +13,8 @@ import (
)
func (p *Provider) getRecordID(ctx context.Context, client *http.Client,
recordType string) (recordID string, err error) {
recordType string,
) (recordID string, err error) {
u := &url.URL{
Scheme: "https",
Host: "dns.aliyuncs.com",

View File

@@ -27,7 +27,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
AccessKeyID string `json:"access_key_id"`
AccessSecret string `json:"access_secret"`

View File

@@ -13,7 +13,8 @@ import (
)
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
recordID string, ip netip.Addr) (err error) {
recordID string, ip netip.Addr,
) (err error) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -27,7 +27,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
var providerSpecificSettings struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -36,7 +36,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Key string `json:"key"`
Token string `json:"token"`
@@ -165,7 +166,8 @@ func (p *Provider) setHeaders(request *http.Request) {
// Obtain domain ID.
// See https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records.
func (p *Provider) getRecordID(ctx context.Context, client *http.Client, newIP netip.Addr) (
identifier string, upToDate bool, err error) {
identifier string, upToDate bool, err error,
) {
recordType := constants.A
if newIP.Is6() {
recordType = constants.AAAA

View File

@@ -31,7 +31,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
URL string `json:"url"`
IPv4Key string `json:"ipv4key"`
@@ -66,7 +67,8 @@ func New(data json.RawMessage, domain, owner string,
}
func validateSettings(domain string, url *url.URL,
ipv4Key, ipv6Key string, successRegex regexp.Regexp) (err error) {
ipv4Key, ipv6Key string, successRegex regexp.Regexp,
) (err error) {
err = utils.CheckDomain(domain)
if err != nil {
return fmt.Errorf("%w: %w", errors.ErrDomainNotValid, err)

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Password string `json:"password"`
}{}

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
}{}

View File

@@ -27,7 +27,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
}{}
@@ -106,7 +107,8 @@ func (p *Provider) setCommonHeaders(request *http.Request) {
}
func (p *Provider) getRecordID(ctx context.Context, recordType string, client *http.Client) (
recordID int, err error) {
recordID int, err error,
) {
values := url.Values{}
values.Set("name", utils.BuildURLQueryHostname(p.owner, p.domain))
values.Set("type", recordType)

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
}{}

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
provider *Provider, err error) {
provider *Provider, err error,
) {
var providerSpecificSettings struct {
Token string `json:"token"`
Secret string `json:"secret"`

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"` // retro-compatibility

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Key string `json:"key"`
}{}
@@ -178,7 +179,8 @@ func (p *Provider) defaultURLValues() (values url.Values) {
}
func (p *Provider) getRecords(ctx context.Context, client *http.Client) (
records dreamHostRecords, err error) {
records dreamHostRecords, err error,
) {
u := url.URL{
Scheme: "https",
Host: "api.dreamhost.com",

View File

@@ -32,7 +32,8 @@ const eTLD = "duckdns.org"
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
// Note domain is of the form:
// - for retro-compatibility: "", "duckdns.org"
// - domain.duckdns.org since duckdns.org is an eTLD.

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"` // Retro-compatibility

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -26,7 +26,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
}{}

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Token string `json:"token"`
@@ -107,7 +108,8 @@ func (p *Provider) HTML() models.HTMLRow {
}
func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Addr) (
newIP netip.Addr, err error) {
newIP netip.Addr, err error,
) {
u := url.URL{
Scheme: "https",
Host: "api.cp.easydns.com",

View File

@@ -31,7 +31,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
provider *Provider, err error) {
provider *Provider, err error,
) {
var providerSpecificSettings struct {
// TODO adapt to the provider specific settings.
Username string `json:"username"`

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
}{}

View File

@@ -34,7 +34,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
PersonalAccessToken string `json:"personal_access_token"`
APIKey string `json:"key"`

View File

@@ -25,7 +25,8 @@ type recordResourceSet struct {
}
func (p *Provider) getRRSet(ctx context.Context, client *http.Client, fqdn, recordType string) (
rrSet *recordResourceSet, err error) {
rrSet *recordResourceSet, err error,
) {
urlPath := fmt.Sprintf("/dns/v1/projects/%s/managedZones/%s/rrsets/%s/%s",
p.project, p.zone, fqdn, recordType)
request, err := http.NewRequestWithContext(ctx, http.MethodGet, makeAPIURL(urlPath), nil)
@@ -66,7 +67,8 @@ func (p *Provider) getRRSet(ctx context.Context, client *http.Client, fqdn, reco
}
func (p *Provider) createRRSet(ctx context.Context, client *http.Client, fqdn, recordType string,
ip netip.Addr) (err error) {
ip netip.Addr,
) (err error) {
urlPath := fmt.Sprintf("/dns/v1/projects/%s/managedZones/%s/rrsets", p.project, p.zone)
body := bytes.NewBuffer(nil)
encoder := json.NewEncoder(body)
@@ -100,7 +102,8 @@ func (p *Provider) createRRSet(ctx context.Context, client *http.Client, fqdn, r
}
func (p *Provider) patchRRSet(ctx context.Context, client *http.Client, fqdn, recordType string,
ip netip.Addr) (err error) {
ip netip.Addr,
) (err error) {
urlPath := fmt.Sprintf("/dns/v1/projects/%s/managedZones/%s/rrsets/%s/%s",
p.project, p.zone, fqdn, recordType)
body := bytes.NewBuffer(nil)

View File

@@ -10,7 +10,8 @@ import (
)
func createOauth2Client(ctx context.Context, client *http.Client, credentialsJSON []byte) (
oauth2Client *http.Client, err error) {
oauth2Client *http.Client, err error,
) {
scopes := []string{
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",

View File

@@ -24,7 +24,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
var extraSettings struct {
Project string `json:"project"`
Zone string `json:"zone"`

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Key string `json:"key"`
Secret string `json:"secret"`

View File

@@ -32,7 +32,8 @@ const defaultDomain = "goip.de"
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
// Note domain is of the form:
// - for retro-compatibility: "", "goip.de" or "goip.it"
// - domain.goip.de or domain.goip.it since goip.de and goip.it are eTLDs.

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Password string `json:"password"`
}{}

View File

@@ -15,7 +15,8 @@ import (
// See https://dns.hetzner.com/api-docs#operation/GetZones.
func (p *Provider) getRecordID(ctx context.Context, client *http.Client, ip netip.Addr) (
identifier string, upToDate bool, err error) {
identifier string, upToDate bool, err error,
) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -27,7 +27,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
ZoneIdentifier string `json:"zone_identifier"`

View File

@@ -15,7 +15,8 @@ import (
)
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
recordID string, ip netip.Addr) (newIP netip.Addr, err error) {
recordID string, ip netip.Addr,
) (newIP netip.Addr, err error) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -15,7 +15,8 @@ import (
)
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
zoneID string, ip netip.Addr) (err error) {
zoneID string, ip netip.Addr,
) (err error) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -14,13 +14,15 @@ import (
)
func (p *Provider) getZones(ctx context.Context, client *http.Client) (
zones []apiZone, err error) {
zones []apiZone, err error,
) {
err = p.get(ctx, client, "/zones", nil, &zones)
return zones, err
}
func (p *Provider) getRecords(ctx context.Context, client *http.Client,
zoneID string, recordType string) (records []apiRecord, err error) {
zoneID string, recordType string,
) (records []apiRecord, err error) {
queryParams := url.Values{
"recordName": []string{p.BuildDomainName()},
"recordType": []string{recordType},
@@ -38,7 +40,8 @@ func (p *Provider) getRecords(ctx context.Context, client *http.Client,
}
func (p *Provider) get(ctx context.Context, client *http.Client,
subPath string, queryParams url.Values, responseJSONData any) (err error) {
subPath string, queryParams url.Values, responseJSONData any,
) (err error) {
u := url.URL{
Scheme: "https",
Host: "api.hosting.ionos.com",

View File

@@ -24,7 +24,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
APIKey string `json:"api_key"`
}{}
@@ -97,7 +98,8 @@ func (p *Provider) HTML() models.HTMLRow {
// See https://developer.hosting.ionos.com/docs/dns
func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Addr) (
newIP netip.Addr, err error) {
newIP netip.Addr, err error,
) {
zones, err := p.getZones(ctx, client)
if err != nil {
return netip.Addr{}, fmt.Errorf("getting zones: %w", err)

View File

@@ -13,7 +13,8 @@ import (
)
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
zoneID string, existingRecord apiRecord, ip netip.Addr) (err error) {
zoneID string, existingRecord apiRecord, ip netip.Addr,
) (err error) {
u := url.URL{
Scheme: "https",
Host: "api.hosting.ionos.com",

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Token string `json:"token"`
}{}
@@ -206,7 +207,8 @@ func (p *Provider) getDomainID(ctx context.Context, client *http.Client) (domain
}
func (p *Provider) getRecordID(ctx context.Context, client *http.Client,
domainID int, recordType string) (recordID int, err error) {
domainID int, recordType string,
) (recordID int, err error) {
u := url.URL{
Scheme: "https",
Host: "api.linode.com",
@@ -254,7 +256,8 @@ func (p *Provider) getRecordID(ctx context.Context, client *http.Client,
}
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
domainID int, recordType string, ip netip.Addr) (err error) {
domainID int, recordType string, ip netip.Addr,
) (err error) {
u := url.URL{
Scheme: "https",
Host: "api.linode.com",
@@ -316,7 +319,8 @@ func (p *Provider) createRecord(ctx context.Context, client *http.Client,
}
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
domainID, recordID int, ip netip.Addr) (err error) {
domainID, recordID int, ip netip.Addr,
) (err error) {
u := url.URL{
Scheme: "https",
Host: "api.linode.com",

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
provider *Provider, err error) {
provider *Provider, err error,
) {
var providerSpecificSettings struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Email string `json:"email"`
Token string `json:"token"`
@@ -55,9 +56,7 @@ func New(data json.RawMessage, domain, owner string,
}, nil
}
var (
regexEmail = regexp.MustCompile(`[a-zA-Z0-9-_.+]+@[a-zA-Z0-9-_.]+\.[a-zA-Z]{2,10}`)
)
var regexEmail = regexp.MustCompile(`[a-zA-Z0-9-_.+]+@[a-zA-Z0-9-_.]+\.[a-zA-Z]{2,10}`)
func validateSettings(domain, email, token string) (err error) {
err = utils.CheckDomain(domain)
@@ -203,7 +202,8 @@ func (p *Provider) getZoneID(ctx context.Context, client *http.Client) (zoneID i
}
func (p *Provider) getRecord(ctx context.Context, client *http.Client, zoneID int, ip netip.Addr) (
record luaDNSRecord, err error) {
record luaDNSRecord, err error,
) {
u := url.URL{
Scheme: "https",
Host: "api.luadns.com",
@@ -258,7 +258,8 @@ func (p *Provider) getRecord(ctx context.Context, client *http.Client, zoneID in
}
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
zoneID int, newRecord luaDNSRecord) (err error) {
zoneID int, newRecord luaDNSRecord,
) (err error) {
u := url.URL{
Scheme: "https",
Host: "api.luadns.com",

View File

@@ -26,7 +26,8 @@ type Provider struct {
}
func New(data json.RawMessage, domain, owner string) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Password string `json:"password"`
}{}

View File

@@ -14,7 +14,8 @@ import (
)
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
ip netip.Addr) (err error) {
ip netip.Addr,
) (err error) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -11,7 +11,8 @@ import (
)
func (p *Provider) getRecordID(ctx context.Context, client *http.Client,
recordType string) (recordID int, err error) {
recordType string,
) (recordID int, err error) {
u := &url.URL{
Scheme: "https",
Host: "api.name.com",

View File

@@ -27,7 +27,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Token string `json:"token"`

View File

@@ -14,7 +14,8 @@ import (
)
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
recordID int, ip netip.Addr) (err error) {
recordID int, ip netip.Addr,
) (err error) {
recordType := constants.A
if ip.Is6() {
recordType = constants.AAAA

View File

@@ -6,7 +6,8 @@ import (
)
func (p *Provider) infoDNSRecords(ctx context.Context, client *http.Client,
session string) (recordSet dnsRecordSet, err error) {
session string,
) (recordSet dnsRecordSet, err error) {
type jsonParams struct {
APIKey string `json:"apikey"`
APISessionID string `json:"apisessionid"`

View File

@@ -13,7 +13,8 @@ import (
)
func doJSONHTTP(ctx context.Context, client *http.Client,
jsonRequestBody, jsonResponseDataTarget any) (err error) {
jsonRequestBody, jsonResponseDataTarget any,
) (err error) {
endpointURL := url.URL{
Scheme: "https",
Host: "ccp.netcup.net",

View File

@@ -9,7 +9,8 @@ import (
)
func (p *Provider) login(ctx context.Context, client *http.Client) (
session string, err error) {
session string, err error,
) {
type jsonParams struct {
APIKey string `json:"apikey"`
APIPassword string `json:"apipassword"`

View File

@@ -26,7 +26,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
var extraSettings struct {
CustomerNumber string `json:"customer_number"`
APIKey string `json:"api_key"`

View File

@@ -11,7 +11,8 @@ import (
func (p *Provider) getRecordToUpdate(ctx context.Context,
client *http.Client, session string, ip netip.Addr) (
record dnsRecord, err error) {
record dnsRecord, err error,
) {
recordSet, err := p.infoDNSRecords(ctx, client, session)
if err != nil {
return record, fmt.Errorf("getting DNS records: %w", err)
@@ -37,7 +38,8 @@ func (p *Provider) getRecordToUpdate(ctx context.Context,
}
func (p *Provider) updateDNSRecords(ctx context.Context, client *http.Client,
session string, recordSet dnsRecordSet) (response dnsRecordSet, err error) {
session string, recordSet dnsRecordSet,
) (response dnsRecordSet, err error) {
type jsonParam struct {
APIKey string `json:"apikey"`
APISessionID string `json:"apisessionid"`

View File

@@ -26,7 +26,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Key string `json:"key"`
}{}

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -10,7 +10,8 @@ import (
)
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
recordType, subdomain, ipStr string, timestamp int64) (err error) {
recordType, subdomain, ipStr string, timestamp int64,
) (err error) {
u := url.URL{
Scheme: p.apiURL.Scheme,
Host: p.apiURL.Host,

View File

@@ -9,7 +9,8 @@ import (
)
func (p *Provider) getRecords(ctx context.Context, client *http.Client,
recordType, subdomain string, timestamp int64) (recordIDs []uint64, err error) {
recordType, subdomain string, timestamp int64,
) (recordIDs []uint64, err error) {
values := url.Values{}
values.Set("fieldType", recordType)
values.Set("subDomain", subdomain)

View File

@@ -15,7 +15,8 @@ func (p *Provider) setHeaderCommon(header http.Header) {
}
func (p *Provider) setHeaderAuth(header http.Header, timestamp int64,
httpMethod string, url *url.URL, body []byte) {
httpMethod string, url *url.URL, body []byte,
) {
header.Add("X-Ovh-Timestamp", strconv.Itoa(int(timestamp)))
header.Add("X-Ovh-Consumer", p.consumerKey)

View File

@@ -37,7 +37,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`
@@ -80,7 +81,8 @@ func New(data json.RawMessage, domain, owner string,
}
func validateSettings(domain, mode, owner, appKey, consumerKey,
appSecret, username, password string) (err error) {
appSecret, username, password string,
) (err error) {
err = utils.CheckDomain(domain)
if err != nil {
return fmt.Errorf("%w: %w", errors.ErrDomainNotValid, err)
@@ -146,7 +148,8 @@ func (p *Provider) HTML() models.HTMLRow {
}
func (p *Provider) updateWithDynHost(ctx context.Context, client *http.Client,
ip netip.Addr) (newIP netip.Addr, err error) {
ip netip.Addr,
) (newIP netip.Addr, err error) {
u := url.URL{
Scheme: "https",
User: url.UserPassword(p.username, p.password),
@@ -198,7 +201,8 @@ func (p *Provider) updateWithDynHost(ctx context.Context, client *http.Client,
}
func (p *Provider) updateWithZoneDNS(ctx context.Context, client *http.Client, ip netip.Addr) (
newIP netip.Addr, err error) {
newIP netip.Addr, err error,
) {
ipStr := ip.Unmap().String()
recordType := constants.A
if ip.Is6() {

View File

@@ -10,7 +10,8 @@ import (
)
func (p *Provider) getAdjustedUnixTimestamp(ctx context.Context, client *http.Client) (
unix int64, err error) {
unix int64, err error,
) {
delta, err := p.getTimeDelta(ctx, client)
if err != nil {
return 0, err

View File

@@ -10,7 +10,8 @@ import (
)
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
recordID uint64, ipStr string, timestamp int64) (err error) {
recordID uint64, ipStr string, timestamp int64,
) (err error) {
u := url.URL{
Scheme: p.apiURL.Scheme,
Host: p.apiURL.Host,

View File

@@ -23,7 +23,8 @@ type dnsRecord struct {
// See https://porkbun.com/api/json/v3/documentation#DNS%20Retrieve%20Records%20by%20Domain,%20Subdomain%20and%20Type
func (p *Provider) getRecords(ctx context.Context, client *http.Client, recordType, owner string) (
records []dnsRecord, err error) {
records []dnsRecord, err error,
) {
url := "https://api.porkbun.com/api/json/v3/dns/retrieveByNameType/" + p.domain + "/" + recordType + "/"
if owner != "@" {
// Note Porkbun requires we send the unescaped '*' character.
@@ -53,7 +54,8 @@ func (p *Provider) getRecords(ctx context.Context, client *http.Client, recordTy
// See https://porkbun.com/api/json/v3/documentation#DNS%20Create%20Record
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
recordType, owner, ipStr string) (err error) {
recordType, owner, ipStr string,
) (err error) {
url := "https://api.porkbun.com/api/json/v3/dns/create/" + p.domain
postRecordsParams := struct {
SecretAPIKey string `json:"secretapikey"`
@@ -82,7 +84,8 @@ func (p *Provider) createRecord(ctx context.Context, client *http.Client,
// See https://porkbun.com/api/json/v3/documentation#DNS%20Edit%20Record%20by%20Domain%20and%20ID
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
recordType, owner, ipStr, recordID string) (err error) {
recordType, owner, ipStr, recordID string,
) (err error) {
url := "https://api.porkbun.com/api/json/v3/dns/edit/" + p.domain + "/" + recordID
postRecordsParams := struct {
SecretAPIKey string `json:"secretapikey"`
@@ -136,7 +139,8 @@ func (p *Provider) deleteRecord(ctx context.Context, client *http.Client, record
//nolint:ireturn
func httpPost[T any](ctx context.Context, client *http.Client,
url string, requestData any, decodeBody bool) (responseData T, err error) {
url string, requestData any, decodeBody bool,
) (responseData T, err error) {
buffer := bytes.NewBuffer(nil)
encoder := json.NewEncoder(buffer)
err = encoder.Encode(requestData)

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
SecretAPIKey string `json:"secret_api_key"`
APIKey string `json:"api_key"`
@@ -179,7 +180,8 @@ func (p *Provider) deleteDefaultConflictingRecordsIfNeeded(ctx context.Context,
// matches the expected content value.
// It returns an error if multiple records are found or if one record is found with an unexpected value.
func (p *Provider) deleteSingleMatchingRecord(ctx context.Context, client *http.Client,
recordType, owner, expectedContent string) (err error) {
recordType, owner, expectedContent string,
) (err error) {
records, err := p.getRecords(ctx, client, recordType, owner)
if err != nil {
return fmt.Errorf("getting records: %w", err)

View File

@@ -78,7 +78,8 @@ func newChangeRRSetRequest(name string, ttl uint32, ip netip.Addr) changeResourc
TTL: ttl,
ResourceRecords: []resourceRecord{{
Value: ip.String(),
}}},
}},
},
}},
},
}

View File

@@ -58,7 +58,8 @@ func Test_changeResourceRecordSetsResponse_XML_Decode(t *testing.T) {
XMLNS: "https://route53.amazonaws.com/doc/2013-04-01/",
XMLName: xml.Name{
Space: "https://route53.amazonaws.com/doc/2013-04-01/",
Local: "ChangeResourceRecordSetsResponse"},
Local: "ChangeResourceRecordSetsResponse",
},
ChangeInfo: xmlChangeInfo{
ID: "/change/FFFFFFFFFFFFFFFFFFFFF",
Status: "PENDING",
@@ -83,7 +84,8 @@ func Test_errorResponse_XML_Decode(t *testing.T) {
XMLNS: "https://route53.amazonaws.com/doc/2013-04-01/",
XMLName: xml.Name{
Space: "https://route53.amazonaws.com/doc/2013-04-01/",
Local: "ErrorResponse"},
Local: "ErrorResponse",
},
Error: xmlError{
Type: "Sender",
Code: "SignatureDoesNotMatch",

View File

@@ -31,7 +31,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
provider *Provider, err error) {
provider *Provider, err error,
) {
var providerSpecificSettings struct {
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`

View File

@@ -26,7 +26,8 @@ type signer struct {
}
func (s *signer) sign(method, urlPath string, payload []byte, date time.Time) (
headerValue string) {
headerValue string,
) {
credentialScope := fmt.Sprintf("%s/%s/%s/%s", date.Format(dateFormat),
s.region, s.service, s.signatureVersion)
credential := fmt.Sprintf("%s/%s", s.accessKey, credentialScope)
@@ -41,7 +42,8 @@ func (s *signer) sign(method, urlPath string, payload []byte, date time.Time) (
}
func buildCanonicalRequest(method, path, headers string, payload []byte) (
canonicalRequest string) {
canonicalRequest string,
) {
canonicalHeaders := "content-type:application/xml\nhost:" + route53Domain + "\n"
const canonicalQuery = "" // no query arg used
payloadHashDigest := hex.EncodeToString(sha256Sum(payload))
@@ -57,7 +59,8 @@ func buildCanonicalRequest(method, path, headers string, payload []byte) (
}
func buildStringToSign(date time.Time,
canonicalRequest, credentialScope string) string {
canonicalRequest, credentialScope string,
) string {
return "AWS4-HMAC-SHA256\n" +
date.Format(dateTimeFormat) + "\n" +
credentialScope + "\n" +

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`

View File

@@ -29,7 +29,8 @@ type Provider struct {
}
func New(data json.RawMessage, domain, owner string, ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
// retro compatibility
if owner == "" {
owner = "@"

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
User string `json:"user"`
Password string `json:"password"`

View File

@@ -28,7 +28,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Password string `json:"password"`
}{}

View File

@@ -29,7 +29,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Email string `json:"email"`
Password string `json:"password"`

View File

@@ -30,7 +30,8 @@ type Provider struct {
func New(data json.RawMessage, domain, owner string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
p *Provider, err error,
) {
extraSettings := struct {
Username string `json:"username"`
Token string `json:"token"`
@@ -108,7 +109,8 @@ func (p *Provider) HTML() models.HTMLRow {
}
func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Addr) (
newIP netip.Addr, err error) {
newIP netip.Addr, err error,
) {
u := url.URL{
Scheme: "https",
Host: "api.cp.zoneedit.com",

View File

@@ -27,7 +27,8 @@ type handlers struct {
var uiFS embed.FS
func newHandler(ctx context.Context, rootURL string,
db Database, runner UpdateForcer) http.Handler {
db Database, runner UpdateForcer,
) http.Handler {
indexTemplate := template.Must(template.ParseFS(uiFS, "ui/index.html"))
staticFolder, err := fs.Sub(uiFS, "ui/static")

View File

@@ -7,7 +7,8 @@ import (
)
func New(ctx context.Context, address, rootURL string, db Database,
logger Logger, runner UpdateForcer) (server *httpserver.Server, err error) {
logger Logger, runner UpdateForcer,
) (server *httpserver.Server, err error) {
return httpserver.New(httpserver.Settings{
Handler: newHandler(ctx, rootURL, db, runner),
Address: &address,

View File

@@ -13,12 +13,11 @@ import (
type getIPFunc func(ctx context.Context) (ip netip.Addr, err error)
var (
ErrIPv6NotSupported = errors.New("IPv6 is not supported on this system")
)
var ErrIPv6NotSupported = errors.New("IPv6 is not supported on this system")
func tryAndRepeatGettingIP(ctx context.Context, getIPFunc getIPFunc,
logger Logger, version ipversion.IPVersion) (ip netip.Addr, err error) {
logger Logger, version ipversion.IPVersion,
) (ip netip.Addr, err error) {
const tries = 3
logMessagePrefix := "obtaining " + version.String() + " address"
errs := make([]error, 0, tries)

View File

@@ -6,7 +6,8 @@ import (
)
func ipv6WithSuffix(publicIP netip.Addr, ipv6Suffix netip.Prefix) (
updateIP netip.Addr) {
updateIP netip.Addr,
) {
if !publicIP.IsValid() || !publicIP.Is6() || !ipv6Suffix.IsValid() {
return publicIP
}

View File

@@ -47,7 +47,8 @@ type loggingRoundTripper struct {
}
func (lrt *loggingRoundTripper) RoundTrip(request *http.Request) (
response *http.Response, err error) {
response *http.Response, err error,
) {
lrt.logger.Debug(requestToString(request))
response, err = lrt.proxied.RoundTrip(request)
@@ -102,7 +103,8 @@ func headerToString(header http.Header) (s string) {
}
func readAndResetBody(body io.ReadCloser) (
newBody io.ReadCloser, bodyString string) {
newBody io.ReadCloser, bodyString string,
) {
b, err := io.ReadAll(body)
if err != nil {
bodyString = "error reading body: " + err.Error()

View File

@@ -34,7 +34,8 @@ type Service struct {
func NewService(db Database, updater UpdaterInterface, ipGetter PublicIPFetcher,
period time.Duration, cooldown time.Duration, logger Logger, resolver LookupIPer,
timeNow func() time.Time, hioClient HealthchecksIOClient) *Service {
timeNow func() time.Time, hioClient HealthchecksIOClient,
) *Service {
return &Service{
period: period,
db: db,
@@ -51,7 +52,8 @@ func NewService(db Database, updater UpdaterInterface, ipGetter PublicIPFetcher,
}
func (s *Service) lookupIPsResilient(ctx context.Context, hostname string, tries int) (
ipv4 netip.Addr, ipv6 netip.Addr, err error) {
ipv4 netip.Addr, ipv6 netip.Addr, err error,
) {
for i := 0; i < tries; i++ {
ipv4, ipv6, err = s.lookupIPs(ctx, hostname)
if err == nil {
@@ -62,7 +64,8 @@ func (s *Service) lookupIPsResilient(ctx context.Context, hostname string, tries
}
func (s *Service) lookupIPs(ctx context.Context, hostname string) (
ipv4 netip.Addr, ipv6 netip.Addr, err error) {
ipv4 netip.Addr, ipv6 netip.Addr, err error,
) {
netIPs, err := s.resolver.LookupIP(ctx, "ip", hostname)
if err != nil {
return netip.Addr{}, netip.Addr{}, err
@@ -106,7 +109,8 @@ func doIPVersion(records []librecords.Record) (doIP, doIPv4, doIPv6 bool) {
}
func (s *Service) getNewIPs(ctx context.Context, doIP, doIPv4, doIPv6 bool) (
ip, ipv4, ipv6 netip.Addr, errors []error) {
ip, ipv4, ipv6 netip.Addr, errors []error,
) {
var err error
if doIP {
ip, err = tryAndRepeatGettingIP(ctx, s.ipGetter.IP, s.logger, ipversion.IP4or6)
@@ -130,7 +134,8 @@ func (s *Service) getNewIPs(ctx context.Context, doIP, doIPv4, doIPv6 bool) (
}
func (s *Service) getRecordIDsToUpdate(ctx context.Context, records []librecords.Record,
ip, ipv4, ipv6 netip.Addr) (recordIDs map[uint]struct{}) {
ip, ipv4, ipv6 netip.Addr,
) (recordIDs map[uint]struct{}) {
recordIDs = make(map[uint]struct{})
for i, record := range records {
shouldUpdate := s.shouldUpdateRecord(ctx, record, ip, ipv4, ipv6)
@@ -143,7 +148,8 @@ func (s *Service) getRecordIDsToUpdate(ctx context.Context, records []librecords
}
func (s *Service) shouldUpdateRecord(ctx context.Context, record librecords.Record,
ip, ipv4, ipv6 netip.Addr) (update bool) {
ip, ipv4, ipv6 netip.Addr,
) (update bool) {
now := s.timeNow()
isWithinCooldown := now.Sub(record.History.GetSuccessTime()) < s.cooldown
@@ -183,7 +189,8 @@ func (s *Service) shouldUpdateRecord(ctx context.Context, record librecords.Reco
}
func (s *Service) shouldUpdateRecordNoLookup(hostname string, ipVersion ipversion.IPVersion,
lastIP, publicIP netip.Addr) (update bool) {
lastIP, publicIP netip.Addr,
) (update bool) {
ipKind := ipVersionToIPKind(ipVersion)
if publicIP.IsValid() && publicIP.Compare(lastIP) != 0 {
s.logInfoNoLookupUpdate(hostname, ipKind, lastIP, publicIP)
@@ -194,7 +201,8 @@ func (s *Service) shouldUpdateRecordNoLookup(hostname string, ipVersion ipversio
}
func (s *Service) shouldUpdateRecordWithLookup(ctx context.Context, hostname string,
ipVersion ipversion.IPVersion, publicIP netip.Addr) (update bool) {
ipVersion ipversion.IPVersion, publicIP netip.Addr,
) (update bool) {
const tries = 5
recordIPv4, recordIPv6, err := s.lookupIPsResilient(ctx, hostname, tries)
if err != nil {
@@ -357,7 +365,8 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, startErr er
}
func (s *Service) run(ctx context.Context, ready chan<- struct{},
done chan<- struct{}) {
done chan<- struct{},
) {
defer close(done)
ticker := time.NewTicker(s.period)
close(ready)

View File

@@ -22,7 +22,8 @@ type Updater struct {
}
func NewUpdater(db Database, client *http.Client, shoutrrrClient ShoutrrrClient,
logger DebugLogger, timeNow func() time.Time) *Updater {
logger DebugLogger, timeNow func() time.Time,
) *Updater {
client = makeLogClient(client, logger)
return &Updater{
db: db,

View File

@@ -79,7 +79,8 @@ func Test_IPv6(t *testing.T) {
func Fuzz_IPv6(f *testing.F) {
f.Fuzz(func(_ *testing.T, ipv6A, ipv6B, ipv6C []byte,
garbageA, garbageB, garbageC string) {
garbageA, garbageB, garbageC string,
) {
var arrayA [16]byte
if len(ipv6A) > 0 {
copy(arrayA[:], ipv6A)

View File

@@ -20,7 +20,8 @@ var (
)
func fetch(ctx context.Context, client Client, network string,
providerData providerData) (publicIPs []netip.Addr, err error) {
providerData providerData,
) (publicIPs []netip.Addr, err error) {
var serverHost string
switch network {
case "tcp":
@@ -80,9 +81,7 @@ func fetch(ctx context.Context, client Client, network string,
return publicIPs, nil
}
var (
ErrTooManyTXTRecords = errors.New("too many TXT records")
)
var ErrTooManyTXTRecords = errors.New("too many TXT records")
func handleAnswerTXT(answer dns.RR) (publicIP netip.Addr, err error) {
answerTXT, ok := answer.(*dns.TXT)

View File

@@ -11,9 +11,7 @@ import (
"github.com/miekg/dns"
)
var (
ErrIPNotFoundForVersion = errors.New("IP addresses found but not for IP version")
)
var ErrIPNotFoundForVersion = errors.New("IP addresses found but not for IP version")
func (f *Fetcher) IP(ctx context.Context) (publicIP netip.Addr, err error) {
publicIPs, err := f.ip(ctx, "tcp")
@@ -52,7 +50,8 @@ func (f *Fetcher) IP6(ctx context.Context) (publicIP netip.Addr, err error) {
}
func (f *Fetcher) ip(ctx context.Context, network string) (
publicIPs []netip.Addr, err error) {
publicIPs []netip.Addr, err error,
) {
index := int(atomic.AddUint32(f.ring.counter, 1)) % len(f.ring.providers)
providerData := f.ring.providers[index].data()

View File

@@ -20,7 +20,8 @@ var (
)
func fetch(ctx context.Context, client *http.Client, url string,
version ipversion.IPVersion) (publicIP netip.Addr, err error) {
version ipversion.IPVersion,
) (publicIP netip.Addr, err error) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return netip.Addr{}, err

View File

@@ -23,7 +23,8 @@ func (f *Fetcher) IP6(ctx context.Context) (publicIP netip.Addr, err error) {
}
func (f *Fetcher) ip(ctx context.Context, ring *urlsRing, version ipversion.IPVersion) (
publicIP netip.Addr, err error) {
publicIP netip.Addr, err error,
) {
ring.mutex.Lock()
var index int

Some files were not shown because too many files have changed in this diff Show More