zone

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: BlueOak-1.0.0 Imports: 10 Imported by: 0

README

go-zone

This library provides methods for parsing DNS zone (master) files as described in RFC 1035 §5.1. A more comprehensive parser is available in https://pkg.golang.ir/github.com/miekg/dns#ZoneParser. The parser in this library will parse files that contain "loose" records whereas the miekg parser strictly requires an origin to be defined.

This library was written to support gdns, a REST API client for the Gandi LiveDNS service, which needs to read individual records from zone-like files so that they can be used to provide values to the remote API.

Example

package main

import (
	"fmt"
	"strings"
	"github.com/jsumners/go-zone"
)

func main() {
	zoneData := "foo 300 in a 1.2.3.4\n"
	zp, _ := zone.NewZoneParser()
	z, _ := zp.Parse(strings.NewReader(zoneData))

	fmt.Println(z)
}

Note On Looseness

Consider the record line:

a in ns

The line is meant to define a nameserver record for the server a. But it is missing the value. Whereas a strict parser will refuse to parse this line, this library will return a ResourceRecord with an empty values list:

ResourceRecord {
	Name: "a",
	Class: "in",
	Type: "ns",
	Values: []string{},
}

For a more complete understanding of the consequences of the looseness of the parser, review the testdata/bind9 fixtures and their expected results. The expectations do not always conform to what Bind would allow. There are further details in the included Readme.

RFCs

Documentation

Overview

Package zone provides methods for parsing DNS zone (master) files as defined in RFC 1035 §5.1.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("feature is not implemented")

Functions

This section is empty.

Types

type Option

type Option func(zp *ZoneParser) error

func WithDefaultTtl

func WithDefaultTtl(value int) Option

WithDefaultTtl allows defining the default TTL that will be used when no $TTL directive has been found. The default is `86_400`. If `WithPreferSoaMinTtl(true)` is used, and a SOA record is present, then this value will be ignored.

func WithPreferSoaMinTtl

func WithPreferSoaMinTtl(value bool) Option

WithPreferSoaMinTtl will _always_ use the minimum TTL value from the SOA line when value is `true`. Any `$TTL` directives will be ignored.

func WithSkipIncludes

func WithSkipIncludes(value bool) Option

type ResourceRecord

type ResourceRecord struct {
	Name   string
	Class  string
	Type   string
	TTL    int
	Values []string
}

func (*ResourceRecord) IsEmpty

func (rr *ResourceRecord) IsEmpty() bool

func (*ResourceRecord) String

func (rr *ResourceRecord) String() string

type Zone

type Zone struct {
	SOA     ResourceRecord
	Records []ResourceRecord
}

func (*Zone) String

func (z *Zone) String() string

type ZoneParser

type ZoneParser struct {
	// contains filtered or unexported fields
}

ZoneParser reads zone master files into Zone objects.

func NewZoneParser

func NewZoneParser(opts ...Option) (*ZoneParser, error)

func (*ZoneParser) Parse

func (zp *ZoneParser) Parse(reader io.Reader) (*Zone, error)

Parse reads the given reader line-by-line as a zone file. All comments are discarded.

Jump to

Keyboard shortcuts

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