artknight / libdns-godaddy

godaddy provider implementation for libdns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Godaddy for libdns

godoc reference

This package implements the libdns interfaces for the Godaddy API

Example

Here's a minimal example of how to get all your DNS records using this libdns provider (see _example/main.go)

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	godaddy "github.com/caoyongzheng/libdns-godday"
	"github.com/libdns/libdns"
)

func main() {
	token := os.Getenv("DNSPOD_TOKEN")
	if token == "" {
		fmt.Printf("DNSPOD_TOKEN not set\n")
		return
	}
	zone := os.Getenv("ZONE")
	if zone == "" {
		fmt.Printf("ZONE not set\n")
		return
	}
	provider := godaddy.Provider{
		APIToken: token,
	}

	records, err := provider.GetRecords(context.TODO(), zone)
	if err != nil {
		log.Fatalln("ERROR: %s\n", err.Error())
	}

	testName := "libdns-test"
	hasTestName := false

	for _, record := range records {
		fmt.Printf("%s (.%s): %s, %s\n", record.Name, zone, record.Value, record.Type)
		if record.Name == testName {
			hasTestName = true
		}
	}

	if !hasTestName {
		appendedRecords, err := provider.AppendRecords(context.TODO(), zone, []libdns.Record{
			libdns.Record{
				Type: "TXT",
				Name: testName,
				TTL:  time.Duration(600) * time.Second,
			},
		})

		if err != nil {
			log.Fatalln("ERROR: %s\n", err.Error())
		}

		fmt.Println("appendedRecords")
		fmt.Println(appendedRecords)
	} else {
		deleteRecords, err := provider.DeleteRecords(context.TODO(), zone, []libdns.Record{
			libdns.Record{
				Type: "TXT",
				Name: testName,
			},
		})

		if err != nil {
			log.Fatalln("ERROR: %s\n", err.Error())
		}

		fmt.Println("deleteRecords")
		fmt.Println(deleteRecords)
	}
}

About

godaddy provider implementation for libdns

License:MIT License


Languages

Language:Go 100.0%