godaddygo

package module
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 8 Imported by: 8

README

godaddygo

Check us out on pkg.go.dev *seems to be a little behind a lot of the time


Table of Contents


Intro


Pull requests welcome! We would like to eventually support each GoDaddy API endpoint, not just domain/DNS related tasks

Installation

  • go get -u github.com/oze4/godaddygo
  • See here for more on how to obtain an API key and API secret from GoDaddy (click 'API Keys')

Getting Started

Bare minimum what you need to get started (aka how you will typically use this package):

package main

import (
	"github.com/oze4/godaddygo"
)

func main() {
	prodKey := "-"
	prodSecret := "-"

	// Target version 1 of the production API
	api := godaddygo.ConnectProduction(prodKey, prodSecret)
	prodv1 := api.V1()

	// Now have access to all GoDaddy production V1
	// API endpoints (via `prodv1`)

	// eg: prodv1.Domain("xyz.com").Records().GetAll()
	//     prodv1.Domain("xyz.com").Records().Add(someDNSRecord)
	//     prodv1.Domain("xyz.com").GetDetails()
	//     prodv1.Domains().My() // <-- List all domains you own
	//     prodv1.Domains().CheckAvailability("dom.com")
	//     prodv1.Domains().Purchase(dom)
	// etc...
}

Usage

GoDaddy's API currently has 2 versions, v1 and v2. Within the godaddygo package we provide 2 helper functions, one for each version. These helper functions simply "wrap" around our "core", which means you have the ability to create yor own client(s).

We recommend using one of the following:

  • godaddygo.ConnectProduction(key, secret)
  • godaddygo.ConnectDevelopment(key, secret)
Default Client
  • If you would like, you may create a default client "manually", then pass it to endpoints.NewAPI(<default_client_here>).
  • At a high level, the godaddygo package is essentially just a wrapper for endpoints and client.
  • All we do is "wrap" those packages within godaddygo, as shown below
package main

import (
	"github.com/oze4/godaddygo/pkg/client"
	"github.com/oze4/godaddygo/pkg/endpoints"
)

func main() {
	// Options for client
	key := "api_key"
	secret := "api_secret"
	// See here for more on GoDaddy production vs development (OTE) API's
	// https://developer.godaddygo.com/getstarted
	targetProductionAPI := true

	// Create default client
	client := client.Default(key, secret, targetProductionAPI)

	// Connect our client to endpoints
	api := endpoints.NewAPI(client)

	//
	// Use `api` here...
	//
	// ...for example:
	prodv1 := api.V1()
	// Target specific domain
	mydom := prodv1.Domain("dom.com")
	// Get all DNS records for target domain
	records, err := mydom.Records().GetAll()

	// ...
}
Custom Client
  • If you wish to use your own client instead of the default client, this is how you would do so.
package main

import (
	"github.com/oze4/godaddygo/pkg/endpoints"
)

func main() {
	myCustomClient := &myClient{
		key:    "api_key",
		secret: "api_secret",
		isprod: true,
	}

	api := endpoints.NewAPI(myCustomClient)

	//
	// Use `api` here!
	//
	// ...
}

// myClient is your custom client
// As long as your client satisfies `client.Interface`
// You can use it to connect to the `endpoints` Gateway
type myClient struct {
	key    string
	secret string
	isprod bool
	// ...your custom stuff
}

func (c *myClient) APIKey() string {
	return c.key
}

func (c *myClient) APISecret() string {
	return c.secret
}

func (c *myClient) IsProduction() string {
	return c.isprod
}

Features

Please see here for more information on GoDaddy API endpoints

  • Abuse
  • Aftermarket
  • Agreements
  • Certificates
  • Countries
  • Domains
    • Check domain availability
    • Get all DNS records
    • Get all DNS records of specific type
    • Get specific DNS record
    • Set DNS record(s)
    • Add/create DNS record(s)
    • Purchase domain
    • Purchase privacy for domain
    • Remove privacy for domain
  • Orders
  • Shoppers
  • Subscriptions




mattoestreich.com


Documentation

Index

Constants

View Source
const (

	// APIProdEnv targets the production API
	APIProdEnv = "prod"
	// APIDevEnv targets the development API
	APIDevEnv = "dev"
	// APIVersion1 specifies version 1
	APIVersion1 = "v1"
	// APIVersion2 specifies version 2
	APIVersion2 = "v2"

	// RecordTypeA defines A record
	RecordTypeA = "A"
	// RecordTypeAAAA defines AAAA record
	RecordTypeAAAA = "AAAA"
	// RecordTypeCNAME defines CNAME record
	RecordTypeCNAME = "CNAME"
	// RecordTypeMX defines MX record
	RecordTypeMX = "MX"
	// RecordTypeNS defines NS record
	RecordTypeNS = "NS"
	// RecordTypeSOA defines SOA record
	RecordTypeSOA = "SOA"
	// RecordTypeSRV defines SRV record
	RecordTypeSRV = "SRV"
	// RecordTypeTXT defines TXT record
	RecordTypeTXT = "TXT"
)

Variables

View Source
var (
	// ErrorWrongStatusCode is the error generated when an incorrect http status code is received
	ErrorWrongStatusCode = fmt.Errorf("ErrorWrongStatusCode")
	// ErrorWrongAPIVersion is the error you get when an incorrect API version is privided within
	// a config
	ErrorWrongAPIVersion = fmt.Errorf("ErrorWrongAPIVersion")
	// ErrorWrongAPIEnv is the error you get when an incorrect API env (production or development)
	// is privided within a config
	ErrorWrongAPIEnv = fmt.Errorf("ErrorWrongAPIEnv: incorrect API env (production or development) privided within config")
)

Functions

This section is empty.

Types

type API added in v1.3.1

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

API connects you to the GoDaddy endpoints

func NewAPI added in v1.3.1

func NewAPI(c *Config) (*API, error)

NewAPI uses a config to connect you to the GoDaddy API

func NewProductionV1 added in v1.3.1

func NewProductionV1(key, secret string) (*API, error)

NewProductionV1 returns a new production v1 API

func (*API) CheckAvailability added in v1.3.1

func (a *API) CheckAvailability(ctx context.Context, name string) error

CheckAvailability checks if a domain is available for purchase

func (*API) Domain added in v1.3.1

func (a *API) Domain(name string) Domain

Domain targets domain endpoint

func (*API) List added in v1.3.1

func (a *API) List(ctx context.Context) ([]string, error)

List returns your domains

func (*API) Purchase added in v1.3.1

func (a *API) Purchase(ctx context.Context, dom DomainDetails) error

Purchase purchases a domain

type AddressMailing added in v1.3.1

type AddressMailing struct {
	Address    string
	Address2   string
	City       string
	Country    string
	PostalCode string
	State      string
}

AddressMailing defines a mailing address

type Config added in v1.3.2

type Config struct {
	Client *http.Client
	// contains filtered or unexported fields
}

Config holds connection options

func NewConfig added in v1.3.2

func NewConfig(key, secret, env, version string) *Config

NewConfig creates a config using `http.DefaultClient` as our client

  • key is the api key
  • secret is the api secret
  • env is whether or not we are targeting prod or dev, use APIDevEnv or APIProdEnv
  • version should be `v1` or `v2`, use APIVersion1 or APIVersion2

func NewConfigWithClient added in v1.3.2

func NewConfigWithClient(key, secret, env, version string, c *http.Client) *Config

NewConfigWithClient creates a config using a custom http client

  • key is the api key
  • secret is the api secret
  • env is whether or not we are targeting prod or dev, use APIDevEnv or APIProdEnv
  • version should be `v1` or `v2`, use APIVersion1 or APIVersion2
  • c is your http client

func (*Config) SetClient added in v1.3.2

func (c *Config) SetClient(h *http.Client)

SetClient allows you to specify your own http client

type Contact added in v1.3.1

type Contact struct {
	AddressMailing AddressMailing
	Email          string
	Fax            string
	JobTitle       string
	NameFirst      string
	NameLast       string
	NameMiddle     string
	Organization   string
	Phone          string
}

Contact defines the details of a contact

type Domain added in v1.3.1

type Domain interface {
	Records() Records
	GetDetails(ctx context.Context) (DomainDetails, error)
}

Domain knows how to interact with the Domains GoDaddy API endpoint

type DomainDetails added in v1.3.1

type DomainDetails struct {
	AuthCode               string
	ContactAdmin           Contact
	ContactBilling         Contact
	ContactRegistrant      Contact
	ContactTech            Contact
	CreatedAt              time.Time
	DeletedAt              time.Time
	TransferAwayEligibleAt time.Time
	Domain                 string
	DomainID               int
	ExpirationProtected    bool
	Expires                time.Time
	ExposeWhois            bool
	HoldRegistrar          bool
	Locked                 bool
	NameServers            []string
	Privacy                bool
	RenewAuto              bool
	RenewDeadline          time.Time
	Status                 string
	SubAccountID           string
	TransferProtected      bool
	Verifications          Verifications
}

DomainDetails defines the details of a domain

type DomainName added in v1.3.1

type DomainName struct {
	Status string
}

DomainName defines a domain name

type RealName added in v1.3.1

type RealName struct {
	Status string
}

RealName defines the real name

type Record added in v1.3.1

type Record struct {
	Data     string
	Name     string
	Port     int
	Priority int
	Protocol string
	Service  string
	TTL      int
	Type     string
	Weight   int
}

Record defines a DNS record

type Records added in v1.3.1

type Records interface {
	List(ctx context.Context) ([]Record, error)
	FindByType(ctx context.Context, t string) ([]Record, error)
	FindByTypeAndName(ctx context.Context, t string, n string) ([]Record, error)
	Update(ctx context.Context, rec Record) error
	Delete(ctx context.Context, rec Record) error
}

Records knows how to interact with the Records GoDaddy API endpoint

type Verifications added in v1.3.1

type Verifications struct {
	DomainName DomainName
	RealName   RealName
}

Verifications defines who verified purchases, etc..

Jump to

Keyboard shortcuts

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