From 973c4175677b3bdc4ae6c0085bb5fb3846c32b38 Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Sun, 16 Jun 2019 18:11:40 +0400 Subject: [PATCH] refactorisation suppression des fmt.println --- main.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index bcdd462..7fe4e42 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,10 @@ var ( configPath string ) +const ( + GandiARecordUrl = "https://dns.api.gandi.net/api/v5/domains/%s/records/@/A" +) + func main() { app := cli.NewApp() @@ -132,7 +136,7 @@ Dns updated successfully for domains func SendStatusMail(messageText string) { settings := configuration.MailSettings - if settings == nil{ + if settings == nil { log.Warnln("no smtp settings defined > status mail not sent") return } @@ -158,8 +162,7 @@ func SendStatusMail(messageText string) { } func GetCurrentIp(configuration Configuration, domain string) (string, error) { - url := fmt.Sprintf("https://dns.api.gandi.net/api/v5/domains/%s/records/@/A", domain) - + url := fmt.Sprintf(GandiARecordUrl, domain) req, err := http.NewRequest("GET", url, nil) if err != nil { return "", err @@ -182,11 +185,11 @@ func GetCurrentIp(configuration Configuration, domain string) (string, error) { } func SetCurrentIp(newip string, domain string, configuration Configuration) error { - url := fmt.Sprintf("https://dns.api.gandi.net/api/v5/domains/%s/records/@/A", domain) - fmt.Println("URL:>", url) + url := fmt.Sprintf(GandiARecordUrl, domain) + log.Infoln("URL:>", url) var str = fmt.Sprintf("{\"rrset_ttl\": %d,\"rrset_values\": [\"%s\"]}", 600, newip) - fmt.Println("json:", str) + log.Infoln("json:", str) var jsonStr = []byte(str) req, err := http.NewRequest("PUT", url, bytes.NewBuffer(jsonStr)) if err != nil { @@ -202,10 +205,10 @@ func SetCurrentIp(newip string, domain string, configuration Configuration) erro } defer resp.Body.Close() - fmt.Println("response Status:", resp.Status) - fmt.Println("response Headers:", resp.Header) + log.Debugln("response Status:", resp.Status) + log.Debugln("response Headers:", resp.Header) body, _ := ioutil.ReadAll(resp.Body) - fmt.Println("response Body:", string(body)) + log.Debugln("response Body:", string(body)) return nil }