-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
helpers.go
59 lines (48 loc) · 1.67 KB
/
helpers.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
48
49
50
51
52
53
54
55
56
57
58
59
package update
import (
"fmt"
"net/netip"
"strings"
"github.com/qdm12/ddns-updater/internal/records"
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
)
func ipVersionToIPKind(version ipversion.IPVersion) (kind string) {
if version == ipversion.IP4or6 {
return "IP"
}
return version.String()
}
func recordToLogString(record records.Record) string {
return fmt.Sprintf("%s (%s)",
record.Provider.BuildDomainName(),
record.Provider.IPVersion())
}
func (r *Runner) logDebugNoLookupSkip(hostname, ipKind string, lastIP, ip netip.Addr) {
r.logger.Debug(fmt.Sprintf("Last %s address stored for %s is %s and your %s address"+
" is %s, skipping update", ipKind, hostname, lastIP, ipKind, ip))
}
func (r *Runner) logInfoNoLookupUpdate(hostname, ipKind string, lastIP, ip netip.Addr) {
r.logger.Info(fmt.Sprintf("Last %s address stored for %s is %s and your %s address is %s",
ipKind, hostname, lastIP, ipKind, ip))
}
func (r *Runner) logDebugLookupSkip(hostname, ipKind string, recordIP, ip netip.Addr) {
r.logger.Debug(fmt.Sprintf("%s address of %s is %s and your %s address"+
" is %s, skipping update", ipKind, hostname, recordIP, ipKind, ip))
}
func (r *Runner) logInfoLookupUpdate(hostname, ipKind string, recordIP, ip netip.Addr) {
r.logger.Info(fmt.Sprintf("%s address of %s is %s and your %s address is %s",
ipKind, hostname, recordIP, ipKind, ip))
}
type joinedErrors struct { //nolint:errname
errs []error
}
func (e *joinedErrors) Error() string {
errorMessages := make([]string, len(e.errs))
for i := range e.errs {
errorMessages[i] = e.errs[i].Error()
}
return strings.Join(errorMessages, ", ")
}
func (e *joinedErrors) Unwrap() []error {
return e.errs
}