mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
DNSPod和Alidns记录信息增加缓存
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
||||
type AliDNSProvider struct {
|
||||
BaseProvider
|
||||
|
||||
ProviderId int64
|
||||
|
||||
accessKeyId string
|
||||
accessKeySecret string
|
||||
regionId string
|
||||
@@ -106,6 +108,11 @@ func (this *AliDNSProvider) GetRecords(domain string) (records []*dnstypes.Recor
|
||||
}
|
||||
}
|
||||
|
||||
// 写入缓存
|
||||
if this.ProviderId > 0 {
|
||||
sharedDomainRecordsCache.WriteDomainRecords(this.ProviderId, domain, records)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -130,6 +137,14 @@ func (this *AliDNSProvider) GetRoutes(domain string) (routes []*dnstypes.Route,
|
||||
|
||||
// QueryRecord 查询单个记录
|
||||
func (this *AliDNSProvider) QueryRecord(domain string, name string, recordType dnstypes.RecordType) (*dnstypes.Record, error) {
|
||||
// 从缓存中读取
|
||||
if this.ProviderId > 0 {
|
||||
record, hasRecords, _ := sharedDomainRecordsCache.QueryDomainRecord(this.ProviderId, domain, name, recordType)
|
||||
if hasRecords { // 有效的搜索
|
||||
return record, nil
|
||||
}
|
||||
}
|
||||
|
||||
records, err := this.GetRecords(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -162,6 +177,12 @@ func (this *AliDNSProvider) AddRecord(domain string, newRecord *dnstypes.Record)
|
||||
}
|
||||
if resp.IsSuccess() {
|
||||
newRecord.Id = resp.RecordId
|
||||
|
||||
// 加入缓存
|
||||
if this.ProviderId > 0 {
|
||||
sharedDomainRecordsCache.AddDomainRecord(this.ProviderId, domain, newRecord)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -183,7 +204,18 @@ func (this *AliDNSProvider) UpdateRecord(domain string, record *dnstypes.Record,
|
||||
|
||||
var resp = alidns.CreateUpdateDomainRecordResponse()
|
||||
err := this.doAPI(req, resp)
|
||||
return this.WrapError(err, domain, newRecord)
|
||||
if err != nil {
|
||||
return this.WrapError(err, domain, newRecord)
|
||||
}
|
||||
|
||||
newRecord.Id = record.Id
|
||||
|
||||
// 修改缓存
|
||||
if this.ProviderId > 0 {
|
||||
sharedDomainRecordsCache.UpdateDomainRecord(this.ProviderId, domain, newRecord)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteRecord 删除记录
|
||||
@@ -193,7 +225,16 @@ func (this *AliDNSProvider) DeleteRecord(domain string, record *dnstypes.Record)
|
||||
|
||||
var resp = alidns.CreateDeleteDomainRecordResponse()
|
||||
err := this.doAPI(req, resp)
|
||||
return this.WrapError(err, domain, record)
|
||||
if err != nil {
|
||||
return this.WrapError(err, domain, record)
|
||||
}
|
||||
|
||||
// 删除缓存
|
||||
if this.ProviderId > 0 {
|
||||
sharedDomainRecordsCache.DeleteDomainRecord(this.ProviderId, domain, record.Id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultRoute 默认线路
|
||||
|
||||
Reference in New Issue
Block a user