// Client() returns a new client for accessing cloudflare. // func (c *Config) Client() (*cloudflare.Client, error) { client, err := cloudflare.NewClient(c.Email, c.Token) if err != nil { return nil, fmt.Errorf("Error setting up client: %s", err) } log.Printf("[INFO] CloudFlare Client configured for user: %s", client.Email) return client, nil }
func UpdateOrSaveRecord(ipaddr string) error { client, err := cf.NewClient(EMAIL, TOKEN) if err != nil { return err } isExists, rc := isRecordExists(client, DOMAIN, RECORD_NAME) if isExists { update := cf.UpdateRecord{} update.Content = ipaddr update.Type = "A" update.Name = RECORD_NAME update.Ttl = "1" err = client.UpdateRecord(rc.Domain, rc.Id, &update) if err != nil { return err } fmt.Printf("Record Updated: %v.%v IN A %v", RECORD_NAME, DOMAIN, ipaddr) } else { create := cf.CreateRecord{} create.Name = RECORD_NAME create.Ttl = "1" create.Type = "A" create.Content = ipaddr _, err := client.CreateRecord(DOMAIN, &create) if err != nil { return err } fmt.Printf("Record Created: %v.%v IN A %v", RECORD_NAME, DOMAIN, ipaddr) } return err }