修改
(record *PorkbunDomainQueryResponse, domain *ddnscore.Domain, recordType string, ipAddr string)
| 121 | |
| 122 | // 修改 |
| 123 | func (pb *Porkbun) modify(record *PorkbunDomainQueryResponse, domain *ddnscore.Domain, recordType string, ipAddr string) { |
| 124 | |
| 125 | // 相同不修改 |
| 126 | if len(record.Records) > 0 && record.Records[0].Content == ipAddr { |
| 127 | if domain.UpdateStatus == ddnscore.UpdatedFailed { |
| 128 | domain.SetDomainUpdateStatus(ddnscore.UpdatedSuccess, "") |
| 129 | } else { |
| 130 | domain.SetDomainUpdateStatus(ddnscore.UpdatedNothing, "") |
| 131 | } |
| 132 | return |
| 133 | } |
| 134 | |
| 135 | var response PorkbunResponse |
| 136 | |
| 137 | err := pb.request( |
| 138 | porkbunEndpoint+fmt.Sprintf("/editByNameType/%s/%s/%s", domain.DomainName, recordType, domain.SubDomain), |
| 139 | &PorkbunDomainCreateOrUpdateVO{ |
| 140 | PorkbunApiKey: &PorkbunApiKey{ |
| 141 | AccessKey: pb.task.DNS.ID, |
| 142 | SecretKey: pb.task.DNS.Secret, |
| 143 | }, |
| 144 | PorkbunDomainRecord: &PorkbunDomainRecord{ |
| 145 | Content: ipAddr, |
| 146 | Ttl: pb.TTL, |
| 147 | }, |
| 148 | }, |
| 149 | &response, |
| 150 | ) |
| 151 | |
| 152 | if err == nil && response.Status == "SUCCESS" { |
| 153 | domain.SetDomainUpdateStatus(ddnscore.UpdatedSuccess, "") |
| 154 | } else { |
| 155 | errMsg := fmt.Sprintf("更新域名解析失败:%v\n", response) |
| 156 | if err != nil { |
| 157 | errMsg += err.Error() |
| 158 | } |
| 159 | domain.SetDomainUpdateStatus(ddnscore.UpdatedFailed, errMsg) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // request 统一请求接口 |
| 164 | func (pb *Porkbun) request(url string, data interface{}, result interface{}) (err error) { |
no test coverage detected