namedotcom

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 13 Imported by: 7

README

name.com for libdns

Go Reference

This package implements the libdns interfaces for name.com, allowing you to manage DNS records.

Authenticating

To initiate the provider you need to supply the following parameters:

provider := namedotcom.Provider {
	Token : "NAMEDOTCOM_API_TOKEN",
	User :  "NAMEDOTCOM_USER_NAME",
	Server: "https://api.name.com", // full url scheme expected here..
}

Example

Here's a basic example of how to list, update and delete records using this provider

package main

import (
	"context"
	"github.com/libdns/libdns"
	"os"
	"github.com/libdns/namedotcom"
	"log"
)

func main() {
	ctx := context.Background()

	zone := "example.com."

	// configure the name.com DNS provider 
	provider := namedotcom.Provider{
		Token : os.GetEnv("NAMEDOTCOM_API_TOKEN"),
		User :     os.GetEnv("NAMEDOTCOM_USER_NAME"),
		Server:    os.GetEnv("NAMEDOTCOM_SERVER"),
	}

	// list and iterate through all records
	recs, err := provider.GetRecords(ctx, zone)
	if err != nil {
		log.Fatal(err)
	}

	for _, rec := range recs {
		log.Println(rec)
	}


	// attempts an upsert, PUT or POST for the given record
	newRecs, err = provider.SetRecords(ctx, zone, []libdns.Record{
		Type:  "A",
		Name:  "sub",
		Value: "1.2.3.4",
	})

	// delete records deletes the given record by ID.
	deletedRecs, err = provider.DeleteRecords(ctx, zone, []libdns.Record{
		Type:  "A",
		Name:  "sub",
		Value: "1.2.3.4",
	})

}

Documentation

Overview

Implements the libdns interfaces for name.com https://www.name.com/api-docs

Index

Constants

View Source
const HTTP_TIMEOUT = 30

default timeout for the http request handler (seconds)

Variables

This section is empty.

Functions

func NewNameDotComClient

func NewNameDotComClient(ctx context.Context, token, user, server string) (*nameDotCom, error)

NewNameDotComClient returns a new name.com client struct

Types

type Provider

type Provider struct {
	Token  string `json:"api_token,omitempty"`
	User   string `json:"user,omitempty"`
	Server string `json:"server,omitempty"` // e.g. https://api.name.com or https://api.dev.name.com
	// contains filtered or unexported fields
}

Provider implements the libdns interface for namedotcom

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

Jump to

Keyboard shortcuts

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