(recordType, ipAddr string, domain *ddnscore.Domain)
| 74 | } |
| 75 | |
| 76 | func (cf *Cloudflare) createUpdateDomain(recordType, ipAddr string, domain *ddnscore.Domain) { |
| 77 | result, err := cf.getZones(domain) |
| 78 | if err != nil || len(result.Result) != 1 { |
| 79 | errMsg := "更新失败[001]:\n" |
| 80 | if err != nil { |
| 81 | errMsg += err.Error() |
| 82 | } else { |
| 83 | errMsg += fmt.Sprintf("%v", result) |
| 84 | } |
| 85 | domain.SetDomainUpdateStatus(ddnscore.UpdatedFailed, errMsg) |
| 86 | return |
| 87 | } |
| 88 | zoneID := result.Result[0].ID |
| 89 | |
| 90 | var records CloudflareRecordsResp |
| 91 | // getDomains 最多更新前50条 |
| 92 | err = cf.request( |
| 93 | "GET", |
| 94 | fmt.Sprintf(zonesAPI+"/%s/dns_records?type=%s&name=%s&per_page=50", zoneID, recordType, domain), |
| 95 | nil, |
| 96 | &records, |
| 97 | ) |
| 98 | |
| 99 | if err != nil || !records.Success { |
| 100 | errMsg := "更新失败[002]:\n" |
| 101 | if err != nil { |
| 102 | errMsg += err.Error() |
| 103 | } |
| 104 | domain.SetDomainUpdateStatus(ddnscore.UpdatedFailed, errMsg) |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | if len(records.Result) > 0 { |
| 109 | // 更新 |
| 110 | cf.modify(records, zoneID, domain, recordType, ipAddr) |
| 111 | } else { |
| 112 | // 新增 |
| 113 | cf.create(zoneID, domain, recordType, ipAddr) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // 创建 |
| 118 | func (cf *Cloudflare) create(zoneID string, domain *ddnscore.Domain, recordType string, ipAddr string) { |
nothing calls this directly
no test coverage detected