package gandi import ( "fmt" "ncddns/mod" "github.com/go-gandi/go-gandi" "github.com/go-gandi/go-gandi/config" "github.com/go-gandi/go-gandi/livedns" ) var ( gandiEmailRecords = []livedns.DomainRecord{ { RrsetType: "MX", RrsetTTL: 10800, RrsetName: "@", RrsetValues: []string{"10 spool.mail.gandi.net.", "50 fb.mail.gandi.net."}, }, { RrsetType: "TXT", RrsetTTL: 10800, RrsetName: "@", RrsetValues: []string{`"v=spf1 include:_mailcust.gandi.net ?all"`}, }, } ) type Client struct{} func (g Client) IPSet(reqs []mod.IPSetRequest) error { if len(reqs) == 0 { return nil } if err := g.EnsureAllDomainsAreSame(reqs); err != nil { return err } pwd := reqs[0].Password domain := reqs[0].Domain records := make([]livedns.DomainRecord, len(reqs)) for index, req := range reqs { records[index] = livedns.DomainRecord{ RrsetType: "A", RrsetTTL: 300, RrsetName: req.Host, RrsetValues: []string{req.IP}, } } records = append(records, gandiEmailRecords...) _, err := gandi.NewLiveDNSClient(config.Config{ APIKey: pwd, }).UpdateDomainRecords(domain, records) return err } func (Client) EnsureAllDomainsAreSame(reqs []mod.IPSetRequest) error { first := reqs[0].Domain for _, dom := range reqs { if first != dom.Domain { return fmt.Errorf("domain mismatch: %s != %s", first, dom.Domain) } } return nil }