godaddygo

package module
v0.0.0-...-e40a90e Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 11 Imported by: 0

README

godaddygo

Check us out on pkg.go.dev


Table of Contents


Intro


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

Installation

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

Usage

Basic Usage

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() {
	key := "<your_key>"
	secret := "<your_secret>"

	// Target production GoDaddy API
	// 99% of the time this is what you are looking for
	api, err := godaddygo.NewProduction(key, secret)
	if err != nil {
		panic(err.Error())
	}

	// Target version 1 of the production API
	godaddy := api.V1()

	//
	// See `Extended Example` section below for more
	//
}

Custom Client

package main

import (
	"net/http"

	"github.com/oze4/godaddygo"
)

func main() {
	key := "<your_key>"
	secret := "<your_secret>"
	// Target production API (godaddygo.APIDevEnv | godaddygo.APIProdEnv)
	target := godaddygo.APIProdEnv

	// Build new config
	myConfig := godaddygo.NewConfig(key, secret, target)
	// Build custom client
	myClient := &http.Client{}

	// Establish "connection" with API
	api, err := godaddygo.WithClient(myClient, myConfig)
	if err != nil {
		panic(err.Error())
	}

	// Target version 1 of the production API
	godaddy := api.V1()

	//
	// See `Extended Example` section below for more
	//
}

Extended Example

Regardless of your client, how you actually use this package will be the same either way.
/* We are continuing from within `main()`
 * ... pretend code from above is here,
 * regardless of your client */

// We now have access to "all" GoDaddy production
// version 1 gateway endpoints (via `godaddy`)

// !! the following is pseudo code !!

foo := godaddy.Domain("foo.com")
bar := godaddy.Domain("bar.com")
// ...more domains...

// Get domain details
foo.GetDetails(ctx)
bar.GetDetails(ctxtwo)

// Anything you can do with `foo`
// you can do with `bar`

// Domain records
fooRecs := foo.Records()
// Do stuff with records
fooRecs.List(ctx)
fooRecs.Add(ctx, someDNSRecord)
fooRecs.FindByType(ctx, godaddygo.RecordTypeA)

// Account related tasks

// View all domains for your account
godaddy.ListDomains(ctx)
// Check availability for domain you don't own
godaddy.CheckAvailability(ctx, "fizz.buzz")
// Purchase domain (this hasn't been tested - it should use the card you have on file)
// I'm not sure what happens when you don't have a card on file =/ lmk
godaddy.Purchase(ctx, myNewDomain)

// etc...

Features

Please see here for more information on GoDaddy Gateway 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)
    • Delete/remove DNS record(s)
    • Purchase domain
    • Purchase privacy for domain
    • Remove privacy for domain
  • Orders
  • Shoppers
  • Subscriptions




mattoestreich.com


Documentation

Index

Constants

View Source
const (
	// Env variables - which godaddy api to target
	APIProdEnv APIEnv = "prod"
	APIDevEnv         = "dev"

	// Allowed API Versions - which version of the godaddy api to target
	APIVersion1 APIVersion = "v1"
	APIVersion2            = "v2"

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

	// Domain statuses (added "Domain" prefix to legacy constants)
	DomainStatusActive    = "ACTIVE"
	DomainStatusCancelled = "CANCELLED"
	// Legacy Domain statuses (to support rename)
	StatusActive    = "ACTIVE"
	StatusCancelled = "CANCELLED"
)

This is a comment so my IDE quits complaining to me

View Source
const (
	// MaxHTTPClientTimeout in seconds is the defalt max http client timeout
	// https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
	// 1 minute by default
	MaxHTTPClientTimeout = time.Second * 60
)

Variables

View Source
var GoDaddyLimiter *rate.Limiter

Functions

This section is empty.

Types

type API

type API interface {
	V1() V1
	V2() V2
}

API knows which version to target

func NewDevelopment

func NewDevelopment(key string, secret string) (API, error)

NewDevelopment targets GoDaddy development API

func NewProduction

func NewProduction(key string, secret string) (API, error)

NewProduction targets GoDaddy production API

func WithClient

func WithClient(client *http.Client, config *Config) (API, error)

WithClient returns API using your own `*http.Client`

type APIEnv

type APIEnv string

APIEnv represents which endpoint to target (dev|prod)

func (APIEnv) IsValid

func (e APIEnv) IsValid() bool

IsValid determines whether or not the given api env is valid

func (APIEnv) String

func (e APIEnv) String() string

type APIURL

type APIURL string

APIURL represents which URL to target

func (APIURL) IsValid

func (u APIURL) IsValid() bool

IsValid determines whether or not the given api url is valid

func (APIURL) String

func (u APIURL) String() string

type APIVersion

type APIVersion string

APIVersion represents which endpoint version to target (v1|v2)

func (APIVersion) IsValid

func (v APIVersion) IsValid() bool

IsValid determines whether or not the given api version is valid

func (APIVersion) String

func (v APIVersion) String() string

type AddressMailing

type AddressMailing struct {
	Address    string `json:"address1,omitempty"`
	Address2   string `json:"address2,omitempty"`
	City       string `json:"city,omitempty"`
	Country    string `json:"country,omitempty"`
	PostalCode string `json:"postalCode,omitempty"`
	State      string `json:"state,omitempty"`
}

AddressMailing defines a mailing address

func (*AddressMailing) FullAddress

func (am *AddressMailing) FullAddress() string

FullAddress returns the full address (Address + Address2)

type Config

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

Config holds connection options. Use `.NewConfig` to create a new config

func NewConfig

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

NewConfig creates a new config

type Contact

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

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

Domain knows how to interact with the Domains GoDaddy Gateway endpoint

type DomainAvailability

type DomainAvailability struct {
	Available  bool   `json:"available,omitempty"`
	Currency   string `json:"currency,omitempty"`
	Definitive bool   `json:"definitive,omitempty"`
	Domain     string `json:"domain,omitempty"`
	Period     int    `json:"period,omitempty"`
	Price      int    `json:"price,omitempty"`
}

DomainAvailability holds data about domain availability

type DomainDetails

type DomainDetails struct {
	AuthCode               string        `json:"authCode,omitempty"`
	ContactAdmin           Contact       `json:"contactAdmin,omitempty"`
	ContactBilling         Contact       `json:"contactBilling,omitempty"`
	ContactRegistrant      Contact       `json:"contactRegistrant,omitempty"`
	ContactTech            Contact       `json:"contactTech,omitempty"`
	CreatedAt              time.Time     `json:"createdAt,omitempty"`
	DeletedAt              time.Time     `json:"deletedAt,omitempty"`
	TransferAwayEligibleAt time.Time     `json:"transferAwayEligibleAt,omitempty"`
	Domain                 string        `json:"domain,omitempty"`
	DomainID               int           `json:"domainId,omitempty"`
	ExpirationProtected    bool          `json:"expirationProtected,omitempty"`
	Expires                time.Time     `json:"expires,omitempty"`
	ExposeWhois            bool          `json:"exposeWhois,omitempty"`
	HoldRegistrar          bool          `json:"holdRegistrar,omitempty"`
	Locked                 bool          `json:"locked,omitempty"`
	NameServers            []string      `json:"nameServers,omitempty"`
	Privacy                bool          `json:"privacy,omitempty"`
	RenewAuto              bool          `json:"renewAuto,omitempty"`
	RenewDeadline          time.Time     `json:"renewDeadline,omitempty"`
	Status                 string        `json:"status,omitempty"`
	SubAccountID           string        `json:"subAccountId,omitempty"`
	TransferProtected      bool          `json:"transferProtected,omitempty"`
	Verifications          Verifications `json:"verifications,omitempty"`
}

DomainDetails defines the details of a domain

type DomainName

type DomainName struct {
	Status string
}

DomainName defines a domain name

type DomainSummary

type DomainSummary struct {
	CreatedAt              time.Time
	Domain                 string
	DomainID               int
	ExpirationProtected    bool
	Expires                time.Time
	ExposeWhois            bool
	HoldRegistrar          bool
	Locked                 bool
	NameServers            []string
	Privacy                bool
	RenewAuto              bool
	Renewable              bool
	Status                 string
	TransferAwayEligibleAt time.Time
	TransferProtected      bool
}

DomainSummary is what gets returned when listing all of your domains

type RealName

type RealName struct {
	Status string `json:"status,omitempty"`
}

RealName defines the real name

type Record

type Record struct {
	Data     string     `json:"data,omitempty"`
	Name     string     `json:"name,omitempty"`
	Port     int        `json:"port,omitempty"`
	Priority int        `json:"priority,omitempty"`
	Protocol string     `json:"protocol,omitempty"`
	Service  string     `json:"service,omitempty"`
	TTL      int        `json:"ttl,omitempty"`
	Type     RecordType `json:"type,omitempty"`
	Weight   int        `json:"weight,omitempty"`
}

Record defines a DNS record

type RecordType

type RecordType string

RecordType represents a DNS record type

func (RecordType) IsDeletable

func (r RecordType) IsDeletable() bool

IsDeletable determines if the given record can be deleted or not

func (RecordType) IsValid

func (r RecordType) IsValid() bool

IsValid determines whether or not the given dns recorsd type is valid

func (RecordType) String

func (r RecordType) String() string

type Records

type Records interface {
	List(ctx context.Context) ([]Record, error)
	Add(ctx context.Context, rec []Record) error
	FindByType(ctx context.Context, t RecordType) ([]Record, error)
	FindByTypeAndName(ctx context.Context, t RecordType, n string) ([]Record, error)
	ReplaceByType(ctx context.Context, t RecordType, rec []Record) error
	ReplaceByTypeAndName(ctx context.Context, t RecordType, n string, rec 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 Gateway endpoint

type V1

type V1 interface {
	Domain(name string) Domain
	ListDomains(ctx context.Context) ([]DomainSummary, error)
	CheckAvailability(ctx context.Context, name string, forTransfer bool) (DomainAvailability, error)
	PurchaseDomain(ctx context.Context, dom DomainDetails) error
}

V1 knows how to interact with GoDaddy Gateway version 1

type V2

type V2 interface{}

V2 knows how to interact with GoDaddy Gateway version 2

type Verifications

type Verifications struct {
	DomainName DomainName `json:"domainName,omitempty"`
	RealName   RealName   `json:"realName,omitempty"`
}

Verifications defines who verified purchases, etc..

Jump to

Keyboard shortcuts

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