aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nccli.go35
1 files changed, 21 insertions, 14 deletions
diff --git a/nccli.go b/nccli.go
index 1dec98e..4485f94 100644
--- a/nccli.go
+++ b/nccli.go
@@ -5,7 +5,7 @@ import (
"encoding/xml"
"flag"
"fmt"
- "io/ioutil"
+ "io"
"log"
"net/http"
"os"
@@ -32,7 +32,7 @@ type DNSResultObj struct {
IsSuccess bool `xml:"IsSuccess,attr"`
}
-//Based on: https://www.namecheap.com/support/api/methods/domains-dns/get-hosts/
+// Based on: https://www.namecheap.com/support/api/methods/domains-dns/get-hosts/
type GetResponseObj struct {
XMLName xml.Name `xml:"ApiResponse"`
// Based on: https://www.namecheap.com/support/api/intro/
@@ -111,7 +111,9 @@ func logRecords(hosts []Host) {
// Make the API request to Namecheap.
// Args: endPoint - the api method to call.
-// extraParams (optional) - more params to add to the apiUrl.
+//
+// extraParams (optional) - more params to add to the apiUrl.
+//
// Returns the response byte stream.
func makeReq(baseUrl string, endPoint string, extraParams ...string) ([]byte, error) {
@@ -141,7 +143,7 @@ func makeReq(baseUrl string, endPoint string, extraParams ...string) ([]byte, er
return nil, err
}
- responseData, err := ioutil.ReadAll(response.Body)
+ responseData, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
@@ -150,7 +152,9 @@ func makeReq(baseUrl string, endPoint string, extraParams ...string) ([]byte, er
// Converts user input strings into ints. Errors if input is wrong.
// Args: userChoicesStrs - slice of strings corresponding to user choices.
-// maxVal - the maximum int value allowed as input.
+//
+// maxVal - the maximum int value allowed as input.
+//
// Returns the slice of integers.
func normalizeUserChoices(userChoicesStrs []string, maxVal int) ([]int, error) {
var chosenInts []int
@@ -176,7 +180,8 @@ func normalizeUserChoices(userChoicesStrs []string, maxVal int) ([]int, error) {
// Updates the hostRecords set with new data.
// If an existing (Name, Type) exists, update the first match.
// Args: hostRecords - slice of Host corresponding to DNS records.
-// newHost - the new values to set for the DNS record.
+//
+// newHost - the new values to set for the DNS record.
func updateHostRecordSet(hostRecords []Host, newHost Host) {
for i, host := range hostRecords {
if (host.Name == newHost.Name) && (host.Type == newHost.Type) {
@@ -294,10 +299,11 @@ func getAllRecords(apiUrl string) ([]Host, error) {
// Add a DNS record.
// Args: rName - the name of the DNS record.
-// rType - the type of the DNS record.
-// rAddress - the value of the DNS record.
-// rMXPref - the priority of the DNS record.
-// rTTL - the ttl of the DNS record.
+//
+// rType - the type of the DNS record.
+// rAddress - the value of the DNS record.
+// rMXPref - the priority of the DNS record.
+// rTTL - the ttl of the DNS record.
func addRecord(apiUrl string, rName string, rType string, rAddress string, rMXPref int, rTTL int) error {
// we need to get the records before we can add to it.
hostRecords, err := getAllRecords(apiUrl)
@@ -363,10 +369,11 @@ func removeRecord(apiUrl string) error {
// Update DNS record.
// Args: rName - the name of the DNS record.
-// rType - the type of the DNS record.
-// rAddress - the value of the DNS record.
-// rMXPref - the priority of the DNS record.
-// rTTL - the ttl of the DNS record.
+//
+// rType - the type of the DNS record.
+// rAddress - the value of the DNS record.
+// rMXPref - the priority of the DNS record.
+// rTTL - the ttl of the DNS record.
func updateRecord(apiUrl string, rName string, rType string, rAddress string, rMXPref int, rTTL int) error {
// we need to get the records before we can update it.
hostRecords, err := getAllRecords(apiUrl)