refactorisation
suppression des fmt.println
This commit is contained in:
parent
021ddabb74
commit
973c417567
21
main.go
21
main.go
@ -45,6 +45,10 @@ var (
|
|||||||
configPath string
|
configPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
GandiARecordUrl = "https://dns.api.gandi.net/api/v5/domains/%s/records/@/A"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
@ -132,7 +136,7 @@ Dns updated successfully for domains
|
|||||||
func SendStatusMail(messageText string) {
|
func SendStatusMail(messageText string) {
|
||||||
|
|
||||||
settings := configuration.MailSettings
|
settings := configuration.MailSettings
|
||||||
if settings == nil{
|
if settings == nil {
|
||||||
log.Warnln("no smtp settings defined > status mail not sent")
|
log.Warnln("no smtp settings defined > status mail not sent")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -158,8 +162,7 @@ func SendStatusMail(messageText string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetCurrentIp(configuration Configuration, domain string) (string, error) {
|
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)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -182,11 +185,11 @@ func GetCurrentIp(configuration Configuration, domain string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetCurrentIp(newip string, domain string, configuration Configuration) 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)
|
url := fmt.Sprintf(GandiARecordUrl, domain)
|
||||||
fmt.Println("URL:>", url)
|
log.Infoln("URL:>", url)
|
||||||
|
|
||||||
var str = fmt.Sprintf("{\"rrset_ttl\": %d,\"rrset_values\": [\"%s\"]}", 600, newip)
|
var str = fmt.Sprintf("{\"rrset_ttl\": %d,\"rrset_values\": [\"%s\"]}", 600, newip)
|
||||||
fmt.Println("json:", str)
|
log.Infoln("json:", str)
|
||||||
var jsonStr = []byte(str)
|
var jsonStr = []byte(str)
|
||||||
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(jsonStr))
|
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(jsonStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -202,10 +205,10 @@ func SetCurrentIp(newip string, domain string, configuration Configuration) erro
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
fmt.Println("response Status:", resp.Status)
|
log.Debugln("response Status:", resp.Status)
|
||||||
fmt.Println("response Headers:", resp.Header)
|
log.Debugln("response Headers:", resp.Header)
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
fmt.Println("response Body:", string(body))
|
log.Debugln("response Body:", string(body))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user