go-powerdns icon indicating copy to clipboard operation
go-powerdns copied to clipboard

Go client library for accessing the PowerDNS API

PowerDNS client library for Go

GoDoc Build Status Maintainability

This package contains a Go library for accessing the PowerDNS Authoritative API.

Supported features

  • [x] Servers
  • [x] Zones
  • [x] Cryptokeys
  • [ ] Metadata
  • [ ] TSIG Keys
  • [x] Searching
  • [ ] Statistics
  • [x] Cache

Installation

Install using go get:

> go get github.com/mittwald/go-powerdns

Usage

First, instantiate a client using pdns.New:

client, err := pdns.New(
    pdns.WithBaseURL("http://localhost:8081"),
    pdns.WithAPIKeyAuthentication("supersecret"),
)

The client then offers more specialiced sub-clients, for example for managing server and zones. Have a look at this library's documentation for more information.

Complete example

package main

import "context"
import "github.com/mittwald/go-powerdns"
import "github.com/mittwald/go-powerdns/apis/zones"

func main() {
    client, err := pdns.New(
        pdns.WithBaseURL("http://localhost:8081"),
        pdns.WithAPIKeyAuthentication("supersecret"),
    )
	
    if err != nil {
    	panic(err)
    }
    
    client.Zones().CreateZone(context.Background(), "localhost", zones.Zone{
        Name: "mydomain.example.",
        Type: zones.ZoneTypeZone,
        Kind: zones.ZoneKindNative,
        Nameservers: []string{
            "ns1.example.com.",
            "ns2.example.com.",
        },
        ResourceRecordSets: []zones.ResourceRecordSet{
            {Name: "foo.mydomain.example.", Type: "A", TTL: 60, Records: []zones.Record{{Content: "127.0.0.1"}}},
        },
    })
}