refactorisation
suppression des fmt.println
This commit is contained in:
parent
021ddabb74
commit
973c417567
19
main.go
19
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()
|
||||||
@ -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