Skip to content

mittwald/go-powerdns

Repository files navigation

PowerDNS client library for Go

GoDoc Build Status Maintainability

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

Supported features

  • Servers
  • Zones
  • Cryptokeys
  • Metadata
  • TSIG Keys
  • Searching
  • Statistics
  • 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"}}},
        },
    })
}