diff options
Diffstat (limited to 'api.go')
| -rw-r--r-- | api.go | 60 | 
1 files changed, 30 insertions, 30 deletions
@@ -1,7 +1,7 @@  // This is a simple example  package cloudflare -import 	( +import (  	"encoding/json"  	"io/ioutil"  	"net/http" @@ -10,20 +10,20 @@ import 	(  )  /* -    This function should run each time -    the user chanegs anything in the GUi -    or each time something in general changes -    -    It returns a RR record which then can be -    turned into JSON and sent via http -    to cloudflare's API +This function should run each time +the user chanegs anything in the GUi +or each time something in general changes + +It returns a RR record which then can be +turned into JSON and sent via http +to cloudflare's API  */  func DoChange() *RRT {  	var dnsRow *RRT  	dnsRow = new(RRT)  	log.Log(INFO, "DoChange() START") -	if (CFdialog.proxyNode.String() == "On") { +	if CFdialog.proxyNode.String() == "On" {  		dnsRow.Proxied = true  	} else {  		dnsRow.Proxied = false @@ -44,7 +44,7 @@ func DoChange() *RRT {  	// show the JSON  	log.Log(INFO, dnsRow) -	if (CFdialog.curlNode != nil) { +	if CFdialog.curlNode != nil {  		pretty, _ := FormatJSON(dnsRow.data)  		log.Log(INFO, "http PUT curl =", pretty)  		CFdialog.curlNode.SetText(pretty) @@ -54,36 +54,36 @@ func DoChange() *RRT {  func SetRow(dnsRow *RRT) {  	log.Log(INFO, "Look for changes in row", dnsRow.ID) -	if (CFdialog.proxyNode != nil) { +	if CFdialog.proxyNode != nil {  		log.Log(INFO, "Proxy", dnsRow.Proxied, "vs", CFdialog.proxyNode.String()) -		if (dnsRow.Proxied == true) { +		if dnsRow.Proxied == true {  			CFdialog.proxyNode.SetText("On")  		} else {  			CFdialog.proxyNode.SetText("Off")  		}  	} -	if (CFdialog.zoneNode != nil) { +	if CFdialog.zoneNode != nil {  		CFdialog.zoneNode.SetText(dnsRow.Domain)  	} -	if (CFdialog.zoneIdNode != nil) { +	if CFdialog.zoneIdNode != nil {  		CFdialog.zoneIdNode.SetText(dnsRow.ZoneID)  	}  	log.Log(INFO, "zoneIdNode =", dnsRow.ZoneID) -	if (CFdialog.rrNode != nil) { +	if CFdialog.rrNode != nil {  		CFdialog.rrNode.SetText(dnsRow.ID)  	} -	if (CFdialog.ValueNode != nil) { +	if CFdialog.ValueNode != nil {  		log.Log(INFO, "Content", dnsRow.Content, "vs", CFdialog.ValueNode.String())  		CFdialog.ValueNode.SetText(dnsRow.Content)  	} -	if (CFdialog.NameNode != nil) { +	if CFdialog.NameNode != nil {  		CFdialog.NameNode.SetText(dnsRow.Name)  	} -	if (CFdialog.TypeNode != nil) { +	if CFdialog.TypeNode != nil {  		CFdialog.TypeNode.SetText(dnsRow.Type)  	} -	if (CFdialog.urlNode != nil) { +	if CFdialog.urlNode != nil {  		url := cloudflareURL + dnsRow.ZoneID + "/dns_records/" + dnsRow.ID  		CFdialog.urlNode.SetText(url)  	} @@ -91,7 +91,7 @@ func SetRow(dnsRow *RRT) {  	// show the JSON  	tmp := makeJSON(dnsRow)  	log.Spew(tmp) -	if (CFdialog.curlNode != nil) { +	if CFdialog.curlNode != nil {  		pretty, _ := FormatJSON(tmp)  		log.Spew("http PUT curl =", pretty)  		CFdialog.curlNode.SetText(pretty) @@ -108,7 +108,7 @@ func GetZonefile(c *ConfigT) *DNSRecords {  	}  	// Set headers -	req.Header.Set("Authorization", "Bearer " + c.Auth) +	req.Header.Set("Authorization", "Bearer "+c.Auth)  	// req.Header.Set("X-Auth-Key", c.Auth)  	// req.Header.Set("X-Auth-Email", c.Email) @@ -147,14 +147,14 @@ func GetZonefile(c *ConfigT) *DNSRecords {  }  /* -	pass in a DNS Resource Records (the stuff in a zonefile) +pass in a DNS Resource Records (the stuff in a zonefile) -	This will talk to the cloudflare API and generate a resource record in the zonefile: +This will talk to the cloudflare API and generate a resource record in the zonefile: -	For example: -	gitea.wit.com. 3600 IN CNAME git.wit.com. -	go.wit.com. 3600 IN A 1.1.1.9 -	test.wit.com. 3600 IN NS ns1.wit.com. +For example: +gitea.wit.com. 3600 IN CNAME git.wit.com. +go.wit.com. 3600 IN A 1.1.1.9 +test.wit.com. 3600 IN NS ns1.wit.com.  */  func makeJSON(dnsRow *RRT) string {  	// make a json record to send on port 80 to cloudflare @@ -162,9 +162,9 @@ func makeJSON(dnsRow *RRT) string {  	tmp = `{"content": "` + dnsRow.Content + `", `  	tmp += `"name": "` + dnsRow.Name + `", `  	tmp += `"type": "` + dnsRow.Type + `", ` -	tmp+= `"ttl": "` +  "1" + `", ` +	tmp += `"ttl": "` + "1" + `", `  	tmp += `"comment": "WIT DNS Control Panel"` -	tmp +=  `}` +	tmp += `}`  	return tmp  } @@ -180,7 +180,7 @@ func GetZones(auth, email string) *DNSRecords {  	}  	// Set headers -	req.Header.Set("Authorization", "Bearer " + auth) +	req.Header.Set("Authorization", "Bearer "+auth)  	// req.Header.Set("X-Auth-Key", auth)  	// req.Header.Set("X-Auth-Email", email)  | 
