mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
update dependencies (#1077)
* update dependencies ddns: update libdns to 1.0.0 * rename var
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/libdns/libdns"
|
||||
@@ -70,13 +71,17 @@ func (provider *Provider) updateDomain(ctx context.Context, domain string) error
|
||||
}
|
||||
|
||||
func (provider *Provider) addDomainRecord(ctx context.Context, recType, addr string) error {
|
||||
_, err := provider.Setter.SetRecords(ctx, provider.zone,
|
||||
netipAddr, err := netip.ParseAddr(addr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse error: %v", err)
|
||||
}
|
||||
|
||||
_, err = provider.Setter.SetRecords(ctx, provider.zone,
|
||||
[]libdns.Record{
|
||||
{
|
||||
Type: recType,
|
||||
Name: provider.prefix,
|
||||
Value: addr,
|
||||
TTL: time.Minute,
|
||||
libdns.Address{
|
||||
Name: provider.prefix,
|
||||
IP: netipAddr,
|
||||
TTL: time.Minute,
|
||||
},
|
||||
})
|
||||
return err
|
||||
|
||||
@@ -49,17 +49,23 @@ type Provider struct {
|
||||
func (provider *Provider) SetRecords(ctx context.Context, zone string,
|
||||
recs []libdns.Record) ([]libdns.Record, error) {
|
||||
for _, rec := range recs {
|
||||
provider.recordType = rec.Type
|
||||
provider.ipType = recordToIPType(provider.recordType)
|
||||
provider.ipAddr = rec.Value
|
||||
provider.domain = fmt.Sprintf("%s.%s", rec.Name, strings.TrimSuffix(zone, "."))
|
||||
switch rec.(type) {
|
||||
case libdns.Address:
|
||||
rr := rec.RR()
|
||||
provider.recordType = rr.Type
|
||||
provider.ipType = recordToIPType(provider.recordType)
|
||||
provider.ipAddr = rr.Data
|
||||
provider.domain = fmt.Sprintf("%s.%s", rr.Name, strings.TrimSuffix(zone, "."))
|
||||
|
||||
req, err := provider.prepareRequest(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update a domain: %s. Cause by: %v", provider.domain, err)
|
||||
}
|
||||
if _, err := utils.HttpClient.Do(req); err != nil {
|
||||
return nil, fmt.Errorf("failed to update a domain: %s. Cause by: %v", provider.domain, err)
|
||||
req, err := provider.prepareRequest(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update a domain: %s. Cause by: %v", provider.domain, err)
|
||||
}
|
||||
if _, err := utils.HttpClient.Do(req); err != nil {
|
||||
return nil, fmt.Errorf("failed to update a domain: %s. Cause by: %v", provider.domain, err)
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported record type: %T", rec)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user