https://github.com/libdns/bunny
Bunny.net DNS implementation for libdns
https://github.com/libdns/bunny
Last synced: 4 months ago
JSON representation
Bunny.net DNS implementation for libdns
- Host: GitHub
- URL: https://github.com/libdns/bunny
- Owner: libdns
- License: mit
- Created: 2024-02-08T21:21:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-11T02:03:04.000Z (11 months ago)
- Last Synced: 2025-07-11T06:57:30.426Z (11 months ago)
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bunny.net DNS for [`libdns`](https://github.com/libdns/libdns)
[](https://pkg.go.dev/github.com/libdns/bunny)
This package implements the [libdns interfaces](https://github.com/libdns/libdns) for [Bunny.net](https://docs.bunny.net/reference/bunnynet-api-overview), allowing you to manage DNS records.
## Authenticating
To authenticate you need to supply a Bunny.net [API Key](https://dash.bunny.net/account/settings).
## Example
Here's a minimal example of how to get all DNS records for zone. See also: [provider_test.go](https://github.com/libdns/bunny/blob/master/provider_test.go)
```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.
```go
...
// 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:
```shell
[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
```