You've already forked ddns-updater
Initial Notifiers implementation
This commit is contained in:
@@ -17,6 +17,7 @@ const (
|
||||
envKeyCloudflareZone = "CLOUDFLARE_ZONE"
|
||||
envKeyOnChangeComment = "ON_CHANGE_COMMENT"
|
||||
envKeyCheckIntervalSeconds = "CHECK_INTERVAL_SECONDS"
|
||||
envKeyNotifiers = "NOTIFIERS"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -25,6 +26,7 @@ type Config struct {
|
||||
ApiToken string
|
||||
CloudflareZone string
|
||||
OnChangeComment string
|
||||
Notifiers []string
|
||||
CheckInterval time.Duration
|
||||
}
|
||||
|
||||
@@ -52,11 +54,12 @@ func NewConfig() Config {
|
||||
}
|
||||
|
||||
return Config{
|
||||
DnsRecordsToCheck: parseDNSToCheck(os.Getenv(envKeyDnsToCheck)),
|
||||
DnsRecordsToCheck: parseCommaDelimited(os.Getenv(envKeyDnsToCheck)),
|
||||
PublicIpResolverTag: os.Getenv(envKeyPublicIpResolverTag),
|
||||
ApiToken: os.Getenv(envKeyCloudflareApiKey),
|
||||
CloudflareZone: os.Getenv(envKeyCloudflareZone),
|
||||
OnChangeComment: os.Getenv(envKeyOnChangeComment),
|
||||
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
|
||||
CheckInterval: time.Duration(checkInterval) * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package internal
|
||||
|
||||
import "strings"
|
||||
|
||||
func parseDNSToCheck(data string) []string {
|
||||
func parseCommaDelimited(data string) []string {
|
||||
out := make([]string, 0, strings.Count(data, ",")+1)
|
||||
for _, dns := range strings.Split(data, ",") {
|
||||
if w := strings.TrimSpace(dns); w != "" {
|
||||
for _, item := range strings.Split(data, ",") {
|
||||
if w := strings.TrimSpace(item); w != "" {
|
||||
out = append(out, w)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ func Test_parseDNSToCheck(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := parseDNSToCheck(tt.args.data); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("parseDNSToCheck() = %v, want %v", got, tt.want)
|
||||
if got := parseCommaDelimited(tt.args.data); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("parseCommaDelimited() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user