ns1-go.v2: gopkg.in/ns1/ns1-go.v2/rest/model/dns Index | Examples | Files

package dns

import "gopkg.in/ns1/ns1-go.v2/rest/model/dns"

Package dns contains definitions for NS1 zones/records/answers/etc.



Package Files

answer.go dnssec.go doc.go record.go zone.go

type Alias Uses

type Alias struct {
    Rdata []interface{} `json:"answer"`

Alias is used as an alias for an answer so that the custom marshaler isn't used.

type AliasAnswer Uses

type AliasAnswer Answer

AliasAnswer is a duplicate of Answer.

type Answer Uses

type Answer struct {
    ID  string `json:"id,omitempty"`

    Meta *data.Meta `json:"meta,omitempty"`

    // Answer response data. eg:
    // Av4: [""]
    // Av6: ["2001:db8:85a3::8a2e:370:7334"]
    // MX:  [10, ""]
    Rdata []string `json:"answer"`

    // Region(grouping) that answer belongs to.
    RegionName string `json:"region,omitempty"`

Answer wraps the values of a Record's "filters" attribute

func NewALIASAnswer Uses

func NewALIASAnswer(host string) *Answer

NewALIASAnswer creates an Answer for ALIAS record.

func NewAnswer Uses

func NewAnswer(rdata []string) *Answer

NewAnswer creates a generic Answer with given rdata.

func NewAv4Answer Uses

func NewAv4Answer(host string) *Answer

NewAv4Answer creates an Answer for A record.

func NewAv6Answer Uses

func NewAv6Answer(host string) *Answer

NewAv6Answer creates an Answer for AAAA record.

func NewCAAAnswer Uses

func NewCAAAnswer(flag int, tag, value string) *Answer

NewCAAAnswer creates an Answer for a CAA record.

func NewCNAMEAnswer Uses

func NewCNAMEAnswer(name string) *Answer

NewCNAMEAnswer creates an Answer for CNAME record.

func NewMXAnswer Uses

func NewMXAnswer(pri int, host string) *Answer

NewMXAnswer creates an Answer for MX record.

func NewSRVAnswer Uses

func NewSRVAnswer(priority, weight, port int, target string) *Answer

NewSRVAnswer creates an Answer for SRV record.

func NewTXTAnswer Uses

func NewTXTAnswer(text string) *Answer

NewTXTAnswer creates an Answer for TXT record.

func NewURLFWDAnswer Uses

func NewURLFWDAnswer(from, to string, redirectType, pathForwardingMode, queryForwarding int) *Answer

NewURLFWDAnswer creates an Answer for URLFWD record.

func (*Answer) SetRegion Uses

func (a *Answer) SetRegion(name string)

SetRegion associates a region with this answer.

func (Answer) String Uses

func (a Answer) String() string

func (*Answer) UnmarshalJSON Uses

func (a *Answer) UnmarshalJSON(data []byte) error

UnmarshalJSON parses responses to Answer and attempts to convert Rdata elements to string.

type Delegation Uses

type Delegation struct {
    DNSKey []*Key `json:"dnskey,omitempty"`
    DS     []*Key `json:"ds,omitempty"`
    TTL    int    `json:"ttl,omitempty"`

Delegation holds a list of DNS Keys, a list of DS Keys, and a TTL

type Key Uses

type Key struct {
    Flags     string
    Protocol  string
    Algorithm string
    PublicKey string

Key holds a DNS key

func (*Key) UnmarshalJSON Uses

func (k *Key) UnmarshalJSON(buf []byte) error

UnmarshalJSON parses a Key from a list into a struct

type Keys Uses

type Keys struct {
    DNSKey []*Key `json:"dnskey,omitempty"`
    TTL    int    `json:"ttl,omitempty"`

Keys holds a list of DNS Keys and a TTL

type Record Uses

type Record struct {
    Meta *data.Meta `json:"meta,omitempty"`

    ID              string `json:"id,omitempty"`
    Zone            string `json:"zone"`
    Domain          string `json:"domain"`
    Type            string `json:"type"`
    Link            string `json:"link,omitempty"`
    TTL             int    `json:"ttl,omitempty"`
    UseClientSubnet *bool  `json:"use_client_subnet,omitempty"`

    // Answers must all be of the same type as the record.
    Answers []*Answer `json:"answers"`
    // The records' filter chain.
    Filters []*filter.Filter `json:"filters"`
    // The records' regions.
    Regions data.Regions `json:"regions,omitempty"`

    // Contains the key/value tag information associated to the record
    Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI

    // List of tag key names that should not inherit from the parent zone
    BlockedTags []string `json:"blocked_tags,omitempty"` //Only relevant for DDI

    // Read-only fields
    LocalTags []string `json:"local_tags,omitempty"` // Only relevant for DDI

Record wraps an NS1 /zone/{zone}/{domain}/{type} resource


// Construct the A record
record := dns.NewRecord("test.com", "a", "A")
record.TTL = 300

// Construct primary answer(higher priority)
pAns := dns.NewAv4Answer("")
pAns.Meta.Priority = 1
pAns.Meta.Up = data.FeedPtr{FeedID: "feed1_id"}

// Construct secondary answer(lower priority)
sAns := dns.NewAv4Answer("")
sAns.Meta.Priority = 2
sAns.Meta.Up = data.FeedPtr{FeedID: "feed2_id"}

// Add both answers to record

// Construct and add both filters to the record(ORDER MATTERS)

// Add region 'test' to record(set as down)
record.Regions["test"] = data.Region{Meta: data.Meta{Up: false}}


fmt.Println("Primary answer:")

fmt.Println("Secondary answer:")

fmt.Println("First Filter in Chain:")

fmt.Println("Second Filter in Chain:")



a.test.com A
Primary answer:
Secondary answer:
First Filter in Chain:
Second Filter in Chain:

func NewRecord Uses

func NewRecord(zone string, domain string, t string) *Record

NewRecord takes a zone, domain and record type t and creates a *Record with UseClientSubnet: true & empty Answers.

func (*Record) AddAnswer Uses

func (r *Record) AddAnswer(ans *Answer)

AddAnswer adds an answer to the record.

func (*Record) AddFilter Uses

func (r *Record) AddFilter(fil *filter.Filter)

AddFilter adds a filter to the records' filter chain(ordering of filters matters).

func (*Record) LinkTo Uses

func (r *Record) LinkTo(to string)

LinkTo sets a Record Link to an FQDN. to is the FQDN of the target record whose config should be used. Does not have to be in the same zone.


// Construct the src record
srcRecord := dns.NewRecord("test.com", "a", "A")
srcRecord.TTL = 300
srcRecord.Meta.Priority = 2

linkedRecord := dns.NewRecord("test.com", "l", "A")


l.test.com A

func (*Record) MarshalJSON Uses

func (r *Record) MarshalJSON() ([]byte, error)

MarshalJSON attempts to convert any Rdata elements that cannot be passed as strings to the API to their correct type.

func (Record) String Uses

func (r Record) String() string

type TSIG Uses

type TSIG struct {
    // Key is the encrypted TSIG key(read-only)
    Key string `json:"key,omitempty"`

    // Whether TSIG is enabled for a secondary zone.
    Enabled bool `json:"enabled,omitempty"`
    // Which hashing algorithm
    Hash string `json:"hash,omitempty"`
    // Name of the TSIG key
    Name string `json:"name,omitempty"`

TSIG is a zones transaction signature.

type Zone Uses

type Zone struct {
    // Zones have metadata tables, but no filters act on 'zone-level' meta.
    Meta *data.Meta `json:"meta,omitempty"`

    // Read-only fields
    DNSServers   []string `json:"dns_servers,omitempty"`
    NetworkPools []string `json:"network_pools,omitempty"`
    Pool         string   `json:"pool,omitempty"`       // Deprecated
    LocalTags    []string `json:"local_tags,omitempty"` // Only relevant for DDI

    ID   string `json:"id,omitempty"`
    Zone string `json:"zone,omitempty"`

    TTL        int    `json:"ttl,omitempty"`
    NxTTL      int    `json:"nx_ttl,omitempty"`
    Retry      int    `json:"retry,omitempty"`
    Serial     int    `json:"serial,omitempty"`
    Refresh    int    `json:"refresh,omitempty"`
    Expiry     int    `json:"expiry,omitempty"`
    Hostmaster string `json:"hostmaster,omitempty"`

    // If this is a linked zone, Link points to an existing standard zone,
    // reusing its configuration and records. Link is a zones' domain name.
    Link *string `json:"link,omitempty"`

    // Networks contains the network ids the zone is available. Most zones
    // will be in the NSONE Global Network(which is id 0).
    NetworkIDs []int         `json:"networks,omitempty"`
    Records    []*ZoneRecord `json:"records,omitempty"`

    // Primary contains info to enable slaving of the zone by third party dns servers.
    Primary *ZonePrimary `json:"primary,omitempty"`
    // Secondary contains info for slaving the zone to a primary dns server.
    Secondary *ZoneSecondary `json:"secondary,omitempty"`

    // Whether or not DNSSEC is enabled on the zone. Note we use a pointer so
    // leaving this unset will not change a previous setting.
    DNSSEC *bool `json:"dnssec,omitempty"`

    // Contains the key/value tag information associated to the zone
    Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI

Zone wraps an NS1 /zone resource


z := dns.NewZone("example.com")




func NewZone Uses

func NewZone(zone string) *Zone

NewZone takes a zone domain name and creates a new zone.

func (*Zone) LinkTo Uses

func (z *Zone) LinkTo(to string)

LinkTo sets Link to a target zone domain name and unsets all other configuration properties. No other zone configuration properties (such as refresh, retry, etc) may be specified, since they are all pulled from the target zone. Linked zones, once created, cannot be configured at all and cannot have records added to them. They may only be deleted, which does not affect the target zone at all.

func (*Zone) MakePrimary Uses

func (z *Zone) MakePrimary(secondaries ...ZoneSecondaryServer)

MakePrimary enables Primary, disables Secondary, and sets primary's Secondaries to all provided ZoneSecondaryServers

Example references https://ns1.com/articles/primary-dns-with-ns1


// Secondary/slave dns server info.
secondary := dns.ZoneSecondaryServer{
    IP:     "",
    Port:   53,
    Notify: true,

// Construct the primary/master zone.
domain := "masterzone.example"

masterZone := dns.NewZone(domain)

b, _ := json.MarshalIndent(masterZone, "", "  ")



  "zone": "masterzone.example",
  "primary": {
    "enabled": true,
    "secondaries": [
        "ip": "",
        "port": 53,
        "notify": true

func (*Zone) MakeSecondary Uses

func (z *Zone) MakeSecondary(ip string)

MakeSecondary enables Secondary, disables Primary, and sets secondary's Primary_ip to provided ip. Sets secondary's primary_port to default of 53.

func (Zone) String Uses

func (z Zone) String() string

type ZoneDNSSEC Uses

type ZoneDNSSEC struct {
    Zone       string      `json:"zone,omitempty"`
    Keys       *Keys       `json:"keys,omitempty"`
    Delegation *Delegation `json:"delegation,omitempty"`

ZoneDNSSEC wraps an NS1 /zone/{zone}/dnssec resource

func (ZoneDNSSEC) String Uses

func (d ZoneDNSSEC) String() string

type ZonePrimary Uses

type ZonePrimary struct {
    // Enabled determines whether AXFR queries (and optionally NOTIFY messages)
    // will be enabled for the zone.
    Enabled     bool                  `json:"enabled"`
    Secondaries []ZoneSecondaryServer `json:"secondaries"`

ZonePrimary wraps a Zone's "primary" attribute

type ZoneRecord Uses

type ZoneRecord struct {
    Domain   string      `json:"Domain,omitempty"`
    ID       string      `json:"id,omitempty"`
    Link     string      `json:"link,omitempty"`
    ShortAns []string    `json:"short_answers,omitempty"`
    Tier     json.Number `json:"tier,omitempty"`
    TTL      int         `json:"ttl,omitempty"`
    Type     string      `json:"type,omitempty"`

    // Contains the key/value tag information associated to the zone
    Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI

    // Read-only fields
    LocalTags []string `json:"local_tags,omitempty"` // Only relevant for DDI

ZoneRecord wraps Zone's "records" attribute

type ZoneSecondary Uses

type ZoneSecondary struct {
    // Read-Only fields
    Expired bool    `json:"expired,omitempty"`
    LastXfr int     `json:"last_xfr,omitempty"`
    Status  string  `json:"status,omitempty"`
    Error   *string `json:"error"`

    PrimaryIP   string `json:"primary_ip,omitempty"`
    PrimaryPort int    `json:"primary_port,omitempty"`
    Enabled     bool   `json:"enabled"`

    OtherIPs   []string `json:"other_ips,omitempty"`
    OtherPorts []int    `json:"other_ports,omitempty"`

    TSIG *TSIG `json:"tsig,omitempty"`

ZoneSecondary wraps a Zone's "secondary" attribute

type ZoneSecondaryServer Uses

type ZoneSecondaryServer struct {
    // Read-Only
    NetworkIDs []int `json:"networks,omitempty"`

    IP     string `json:"ip"`
    Port   int    `json:"port,omitempty"`
    Notify bool   `json:"notify"`

ZoneSecondaryServer wraps elements of a Zone's "primary.secondary" attribute

Package dns imports 7 packages (graph) and is imported by 40 packages. Updated 2021-01-27. Refresh now. Tools for package owners.