namecheap

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

README

Go Namecheap SDK

Go Reference Go Report Card

Getting
$ go get github.com/namecheap/go-namecheap-sdk
Usage

Generally callers would create a namecheap.Client and make calls off of that.

import (
    "github.com/namecheap/go-namecheap-sdk"
)

// Reads environment variables
client, err := namecheap.New()

// Directly build client
client, err := namecheap.NewClient(username, apiuser string, token string, ip string, useSandbox)

Calling namecheap.New() reads the following environment variables:

Contributing

We appreciate feedback, issues and Pull Requests. You can build the project with make build in the root and run tests with make test.

If you're looking to run tests yourself you can configure the environmental variables and override the test records in client_test.go. (To make live API calls) Otherwise only mockable tests will run.

The following are contributor oriented environmental variables:

  • DEBUG: Log all responses
  • MOCKED: Force disable testClient

Documentation

Overview

Package namecheap - Golang client for Namecheap's API

To use this project you'll need to either pull down the source or vendor it into your project.

Once added to your project there are two ways to construct a Client

namecheap.New() // reads environmental variables
namecheap.NewClient(username, apiuser string, token string, ip string, useSandbox)

The following environmental variables are supported:

NAMECHEAP_USERNAME        Username: e.g. adamdecaf
NAMECHEAP_API_USER        ApiUser: e.g. adamdecaf
NAMECHEAP_TOKEN           From https://ap.www.namecheap.com/Profile/Tools/ApiAccess
NAMECHEAP_IP              Your IP (must be whitelisted)
NAMECHEAP_USE_SANDBOX     Use sandbox environment

The public methods are viewable here: https://godoc.org/github.com/adamdecaf/namecheap

Please raise an issue or pull request if you run into problems. Thanks!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRecordType

func CheckRecordType(recordType string) bool

func HashString

func HashString(s string) int

HashString hashes a string to a unique hashcode.

crc32 returns a uint32, but for our use we need and non negative integer. Here we cast to an integer and invert it if the result is negative.

func HashStrings

func HashStrings(strings []string) string

HashStrings hashes a list of strings to a unique hashcode.

Types

type Client

type Client struct {
	// Access Token
	Token string

	// ApiUser
	ApiUser string // TODO(adam): What's this for? difference with Username?

	// Username
	Username string

	// URL to the DO API to use
	URL string

	// IP that is whitelisted
	Ip string

	// HttpClient is the client to use. A client with
	// default values will be used if not provided.
	Http *http.Client
}

Client provides a client to the Namecheap API

func New

func New() (*Client, error)

New returns a Client instance by reading environment variables

func NewClient

func NewClient(username string, apiuser string, token string, ip string, useSandbox bool) (*Client, error)

NewClient creates a Client instance from the provided configuration typically users call New() with environment variables set instead.

func (*Client) AddRecord

func (c *Client) AddRecord(domain string, record *Record) (*Record, error)

func (*Client) CreateHash

func (c *Client) CreateHash(record *Record) int

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(domain string, hashId int) error

func (*Client) FindRecordByHash

func (c *Client) FindRecordByHash(hashId int, records []Record) (*Record, error)

func (*Client) GetDomains

func (c *Client) GetDomains() ([]Domain, error)

GetDomains retrieves all the domains available on account.

func (*Client) GetHosts

func (c *Client) GetHosts(domain string) ([]Record, error)

GetHosts retrieves all the records for the given domain.

func (*Client) GetNS

func (c *Client) GetNS(domain string) ([]string, error)

func (*Client) NewRequest

func (c *Client) NewRequest(body map[string]string) (*http.Request, error)

NewRequest creates a new request with the params

func (*Client) ReadRecord

func (c *Client) ReadRecord(domain string, hashId int) (*Record, error)

func (*Client) RemoveRecordByHash

func (c *Client) RemoveRecordByHash(hashId int, records []Record) []Record

func (*Client) ResetNS

func (c *Client) ResetNS(domain string) error

func (*Client) SetHosts

func (c *Client) SetHosts(domain string, records []Record) ([]Record, error)

func (*Client) SetNS

func (c *Client) SetNS(domain string, servers []string) ([]string, error)

func (*Client) UpdateRecord

func (c *Client) UpdateRecord(domain string, hashId int, record *Record) error

type Domain

type Domain struct {
	ID   string `xml:"ID,attr"`
	Name string `xml:"Name,attr"`
}

Domain is used to represent a retrieved Domain. All properties are set as strings.

type DomainsResponse

type DomainsResponse struct {
	XMLName xml.Name `xml:"ApiResponse"`
	Errors  []struct {
		Message string `xml:",chardata"`
		Number  string `xml:"Number,attr"`
	} `xml:"Errors>Error"`
	CommandResponse struct {
		Domains []Domain `xml:"DomainGetListResult>Domain"`
	} `xml:"CommandResponse"`
}

type NSListResponse

type NSListResponse struct {
	XMLName xml.Name `xml:"ApiResponse"`
	Errors  []struct {
		Message string `xml:",chardata"`
		Number  string `xml:"Number,attr"`
	} `xml:"Errors>Error"`
	CommandResponse struct {
		DomainDNSGetListResult []string `xml:"DomainDNSGetListResult>Nameserver"`
	} `xml:"CommandResponse"`
}

type NSSetCustomRepsonse

type NSSetCustomRepsonse struct {
	XMLName xml.Name `xml:"ApiResponse"`
	Errors  []struct {
		Message string `xml:",chardata"`
		Number  string `xml:"Number,attr"`
	} `xml:"Errors>Error"`
	CommandResponse struct {
		DomainDNSSetCustomResult struct {
			Domain  string `xml:"Domain,attr"`
			Updated bool   `xml:"Updated,attr"`
		} `xml:"DomainDNSSetCustomResult"`
	} `xml:"CommandResponse"`
}

type NSSetDefaultResponse

type NSSetDefaultResponse struct {
	XMLName xml.Name `xml:"ApiResponse"`
	Errors  []struct {
		Message string `xml:",chardata"`
		Number  string `xml:"Number,attr"`
	} `xml:"Errors>Error"`
	CommandResponse struct {
		DomainDNSSetDefaultResult struct {
			Domain  string `xml:"Domain,attr"`
			Updated bool   `xml:"Updated,attr"`
		} `xml:"DomainDNSSetDefaultResult"`
	} `xml:"CommandResponse"`
}

type Record

type Record struct {
	Name               string `xml:"Name,attr"`
	FriendlyName       string `xml:"FriendlyName,attr"`
	Address            string `xml:"Address,attr"`
	MXPref             int    `xml:"MXPref,attr"`
	AssociatedAppTitle string `xml:"AssociatedAppTitle,attr"`
	Id                 int    `xml:"HostId,attr"`
	RecordType         string `xml:"Type,attr"`
	TTL                int    `xml:"TTL,attr"`
	IsActive           bool   `xml:"IsActive,attr"`
	IsDDNSEnabled      bool   `xml:"IsDDNSEnabled,attr"`
}

Record is used to represent a retrieved Record. All properties are set as strings.

func RemoveParkingRecords

func RemoveParkingRecords(domain string, records []Record) []Record

func (*Record) Equal

func (r *Record) Equal(other *Record) bool

Equal in the sense that clients would see them as the same

type RecordsCreateResult

type RecordsCreateResult struct {
	XMLName xml.Name `xml:"ApiResponse"`
	Errors  []struct {
		Message string `xml:",chardata"`
		Number  string `xml:"Number,attr"`
	} `xml:"Errors>Error"`
	CommandResponse struct {
		DomainDNSSetHostsResult struct {
			Domain    string `xml:"Domain,attr"`
			IsSuccess bool   `xml:"IsSuccess,attr"`
		} `xml:"DomainDNSSetHostsResult"`
	} `xml:"CommandResponse"`
}

type RecordsResponse

type RecordsResponse struct {
	XMLName xml.Name `xml:"ApiResponse"`
	Errors  []struct {
		Message string `xml:",chardata"`
		Number  string `xml:"Number,attr"`
	} `xml:"Errors>Error"`
	CommandResponse struct {
		Records []Record `xml:"DomainDNSGetHostsResult>host"`
	} `xml:"CommandResponse"`
}

Jump to

Keyboard shortcuts

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