bunny

package module
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 12 Imported by: 7 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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 zone == "" {
		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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// AccessKey is the Bunny.net API key - see https://docs.bunny.net/reference/bunnynet-api-overview
	AccessKey string                        `json:"access_key"`
	Debug     bool                          `json:"debug"`
	Logger    func(string, []libdns.Record) `json:"-"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with Bunny.net

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, domain string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, domain string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, domain string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) ListZones added in v1.5.0

func (p *Provider) ListZones(ctx context.Context) ([]libdns.Zone, error)

ListZones returns the list of available DNS zones.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, domain string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址