Skip to content

Commit

Permalink
Merge pull request #4 from rockingdice/pr-fix-record-name
Browse files Browse the repository at this point in the history
fix record name issue
  • Loading branch information
lscgzwd authored Feb 4, 2021
2 parents b710628 + 2278bf8 commit a77ccca
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@ func (p *Provider) getDNSEntries(ctx context.Context, zone string) ([]libdns.Rec
return records, nil
}

func extractRecordName(name string, zone string) string {
if idx := strings.Index(name, "."+strings.Trim(zone, ".")); idx != -1 {
return name[:idx]
}
return name
}

func (p *Provider) addDNSEntry(ctx context.Context, zone string, record libdns.Record) (libdns.Record, error) {
p.mutex.Lock()
defer p.mutex.Unlock()

p.getClient()

entry := d.Record{
Name: strings.Trim(strings.ReplaceAll(record.Name, strings.Trim(zone, "."), ""), "."),
Name: extractRecordName(record.Name, zone),
Value: record.Value,
Type: record.Type,
Line: "默认",
Expand Down Expand Up @@ -142,7 +149,7 @@ func (p *Provider) updateDNSEntry(ctx context.Context, zone string, record libdn
p.getClient()

entry := d.Record{
Name: strings.Trim(strings.ReplaceAll(record.Name, zone, ""), "."),
Name: extractRecordName(record.Name, zone),
Value: record.Value,
Type: record.Type,
Line: "默认",
Expand Down

0 comments on commit a77ccca

Please sign in to comment.