-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneoserv.go
56 lines (48 loc) · 1.51 KB
/
neoserv.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
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"fmt"
"os"
"github.com/libdns/libdns"
"github.com/libdns/neoserv"
)
// This example demonstrates how to use the Neoserv provider to manage DNS records.
// It requires the following environment variables to be set:
// - NEOSERV_USERNAME: the username for the Neoserv API
// - NEOSERV_PASSWORD: the password for the Neoserv API
// - NEOSERV_ZONE: the zone to manage
// The example will list the existing records, add a new TXT record, and list the added record.
func main() {
username := os.Getenv("NEOSERV_USERNAME")
password := os.Getenv("NEOSERV_PASSWORD")
zone := os.Getenv("NEOSERV_ZONE")
if username == "" || password == "" || zone == "" {
fmt.Println("Please set the NEOSERV_USERNAME, NEOSERV_PASSWORD and NEOSERV_ZONE environment variables.")
os.Exit(1)
}
provider := neoserv.Provider{
Username: username,
Password: password,
}
// Get existing records
records, err := provider.GetRecords(context.TODO(), zone)
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
}
for _, record := range records {
fmt.Printf("%s (ID: %s): %s, %s, TTL: %s\n", record.Name, record.ID, record.Type, record.Value, record.TTL.String())
}
// Add a new record
newRecords, err := provider.AppendRecords(context.TODO(), zone, []libdns.Record{
{
Type: "TXT",
Name: "test",
Value: "This is a test",
TTL: neoserv.TTL12h, // Neoserv supports specific TTL values
},
})
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
}
fmt.Printf("Added: %v\n", newRecords)
}