-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns.go
45 lines (37 loc) · 853 Bytes
/
dns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// dnsCmd represents the dns command
var dnsCmd = &cobra.Command{
Use: "dns",
Short: "DNS cmd lets you host your zones and manage records",
}
// getRecordIDByName get record ID by name
func getRecordIDByName(domainName, recordName string) (int64, error) {
records, err := csDNS.GetRecords(gContext, domainName)
if err != nil {
return 0, err
}
resRecID := []int64{}
for _, r := range records {
id := fmt.Sprintf("%d", r.ID)
if id == recordName {
return r.ID, nil
}
if recordName == r.Name {
resRecID = append(resRecID, r.ID)
}
}
if len(resRecID) > 1 {
return 0, fmt.Errorf("more than one records were found")
}
if len(resRecID) == 1 {
return resRecID[0], nil
}
return 0, fmt.Errorf("no records were found")
}
func init() {
RootCmd.AddCommand(dnsCmd)
}