-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (58 loc) · 1.44 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
// Use the following command line to run this example:
//
// go run _examples/main.go -email your_email -key your_api_key -zone your_zone.com
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"time"
"github.com/libdns/libdns"
"github.com/libdns/luadns"
)
var email string
var key string
var url string
var zone string
func main() {
flag.StringVar(&email, "email", "[email protected]", "your email address")
flag.StringVar(&key, "key", "", "your API key")
flag.StringVar(&zone, "zone", "example.org.", "zone name")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
provider := luadns.Provider{
Email: email,
APIKey: key,
}
ctx := context.Background()
records, err := provider.GetRecords(ctx, zone)
if err != nil {
log.Fatalln(err)
}
fmt.Println("===> Running GetRecords ...")
for _, r := range records {
fmt.Println(r)
}
fmt.Println("===> Running SetRecords ...")
records, err = provider.SetRecords(ctx, zone, records)
if err != nil {
log.Fatalln(err)
}
fmt.Println("===> Running AppendRecords ...")
records, err = provider.AppendRecords(ctx, zone, []libdns.Record{
libdns.Record{Name: "_acme-challenge", Type: "TXT", Value: "Hello, world!", TTL: 3600 * time.Second},
})
if err != nil {
log.Fatalln(err)
}
fmt.Println("===> Running DeleteRecords ...")
_, err = provider.DeleteRecords(ctx, zone, records)
if err != nil {
log.Fatalln(err)
}
}