Esempio n. 1
0
func CmdAdd(c *cli.Context) {
	// Write your code here
	validateRequiredArgs(c)
	domain := c.String("domain")
	ip := c.String("ip")
	var err error

	if ip == "" {
		ip, err = getPublicIp()
	}
	assert(err)

	client := api.BuildClient(c)
	params := make(map[string]string)
	params["type"] = "A"
	params["name"] = domain
	params["content"] = ip
	params["ttl"] = "1"

	var response api.CloudFlareRecordResponse
	err = client.PostAndParse("rec_new", params, &response)

	if err != nil || response.Result == "error" {
		fatal("Error while creating a record: " + response.Msg)
		os.Exit(2)
	}

	println("Successfully created record name=" + response.Response.Rec.Record.Name + " ip=" + response.Response.Rec.Record.Content)

}
Esempio n. 2
0
func CmdList(c *cli.Context) {
	validateRequiredArgs(c)
	client := api.BuildClient(c)
	params := make(map[string]string)
	var response api.CloudflareListResponse
	err := client.PostAndParse("rec_load_all", params, &response)

	if err != nil || response.Result == "error" {
		fatal("Error while retrieving records: " + response.Msg)
		os.Exit(2)
	}

	fmt.Printf("%+v\n", response)
}