A vibe coded tangled fork which supports pijul.
at f93c5f2d96ad307d9b0099b94650637ac2358999 61 lines 1.4 kB view raw
1package cloudflare 2 3import ( 4 "context" 5 "fmt" 6 7 cf "github.com/cloudflare/cloudflare-go/v6" 8 "github.com/cloudflare/cloudflare-go/v6/dns" 9) 10 11type DNSRecord struct { 12 Type string 13 Name string 14 Content string 15 TTL int 16 Proxied bool 17} 18 19func (cl *Client) CreateDNSRecord(ctx context.Context, record DNSRecord) (string, error) { 20 var body dns.RecordNewParamsBodyUnion 21 22 switch record.Type { 23 case "A": 24 body = dns.ARecordParam{ 25 Name: cf.F(record.Name), 26 TTL: cf.F(dns.TTL(record.TTL)), 27 Type: cf.F(dns.ARecordTypeA), 28 Content: cf.F(record.Content), 29 Proxied: cf.F(record.Proxied), 30 } 31 case "CNAME": 32 body = dns.CNAMERecordParam{ 33 Name: cf.F(record.Name), 34 TTL: cf.F(dns.TTL(record.TTL)), 35 Type: cf.F(dns.CNAMERecordTypeCNAME), 36 Content: cf.F(record.Content), 37 Proxied: cf.F(record.Proxied), 38 } 39 default: 40 return "", fmt.Errorf("unsupported DNS record type: %s", record.Type) 41 } 42 43 result, err := cl.api.DNS.Records.New(ctx, dns.RecordNewParams{ 44 ZoneID: cf.F(cl.zone), 45 Body: body, 46 }) 47 if err != nil { 48 return "", fmt.Errorf("failed to create DNS record: %w", err) 49 } 50 return result.ID, nil 51} 52 53func (cl *Client) DeleteDNSRecord(ctx context.Context, recordID string) error { 54 _, err := cl.api.DNS.Records.Delete(ctx, recordID, dns.RecordDeleteParams{ 55 ZoneID: cf.F(cl.zone), 56 }) 57 if err != nil { 58 return fmt.Errorf("failed to delete DNS record: %w", err) 59 } 60 return nil 61}