Skip to content

Latest commit

 

History

History
87 lines (66 loc) · 2.13 KB

README.md

File metadata and controls

87 lines (66 loc) · 2.13 KB

Bunny.net DNS for libdns

Go Reference

This package implements the libdns interfaces for Bunny.net, allowing you to manage DNS records.

Authenticating

To authenticate you need to supply a Bunny.net API Key.

Example

Here's a minimal example of how to get all DNS records for zone. See also: provider_test.go

package main

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

	"github.com/libdns/bunny"
)

func main() {
	apiKey := os.Getenv("BUNNY_API_KEY")
	if apiKey == "" {
		fmt.Printf("BUNNY_API_KEY not set\n")
		return
	}

	zone := os.Getenv("BUNNY_ZONE")
	if token == "" {
		fmt.Printf("BUNNY_ZONE not set\n")
		return
	}

	provider := &bunny.Provider{
		AccessKey: apiKey,
	}

	records, err := provider.GetRecords(context.WithTimeout(context.Background(), time.Duration(15*time.Second)), zone)
	if err != nil {
        fmt.Printf("Error: %s", err.Error())
        return
	}

	fmt.Println(records)
}

Debugging

You can enable logging by configuring a custom logger or by setting Debug to true.

	...

	// Logging is always enabled when using a custom logger
	provider := &bunny.Provider{
		AccessKey: apiKey,
		Logger: func(msg string, records []libdns.Record) {
			fmt.Printf("[bunny]: %s\n", msg)
		}
	}

	// Enable the default logger
	provider := &bunny.Provider{
		AccessKey: apiKey,
		Debug: true
	}

Example output using the default logger:

[bunny] fetching all records in zone example.com
[bunny] fetching zone ID for example.com
[bunny] done found zone ID 82940 for example.com
[bunny] done fetching 3 record(s) in zone example.com
[bunny]   TXT: ID=7648777, TTL=2m0s, Priority=0, Name=test1, Value=test1
[bunny]   TXT: ID=7648778, TTL=2m0s, Priority=0, Name=test2, Value=test2
[bunny]   TXT: ID=7648779, TTL=2m0s, Priority=0, Name=test3, Value=test3
[bunny] deleting TXT record in zone example.com