gostellix

package module
v0.0.0-...-6a2a583 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 10 Imported by: 0

README

gostellix

Simple go library for Constellix API

Example:

package main

import (
	"encoding/json"
	"fmt"
	"gostellix/gostellix"
)

var apikey, secretkey string = "***-***-***-***-***", "***-***-***-***-***"

func checkErr(err error) {
	if err != nil {
		fmt.Println(err)
	}
}

func printStruct(jsonStruct interface{}) {
	json_var, err := json.MarshalIndent(jsonStruct, "", "  ")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(json_var))
}

func main() {
	gstell := gostellix.New(apikey, secretkey)

	var domains []gostellix.ConstellixDomain
	domains, _ = gstell.GetAllDomains()
	for _, domain := range domains {
		// printStruct(domain)
		fmt.Println(domain)
	}

	domainName := "example.com"

	id, err := gstell.GetDomainID(domainName)
	checkErr(err)
	fmt.Printf("ID: %v",id)

	domain, err := gstell.GetDomainByName(domainName)
	checkErr(err)
	printStruct(domain)

	records, err := gstell.GetRecordsByDomainName(domainName)
	checkErr(err)
	printStruct(records)
	for _, item := range records{
		fmt.Printf("type: %v, option: %v \n", item.RecordType, item.RecordOption)
	}
	fmt.Println(len(records))
}
}```

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	APIURL string

	UserAgent  string
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client Client for the Constellix API

func New

func New(apikey, secretkey string) *Client

New Create a new client

func (*Client) APIRequest

func (client *Client) APIRequest(endpoint, params, reqtype string) (response []byte, err error)

APIRequest make an API request

func (*Client) CreateDomainRecord

func (client *Client) CreateDomainRecord(domainID int, record ConstellixRecord) error

CreateDomainRecord add a record to a domain

func (*Client) CreateDomains

func (client *Client) CreateDomains(domains []string) error

CreateDomains Create a list of domains by name

func (*Client) DeleteDomain

func (client *Client) DeleteDomain(id int) error

DeleteDomain delete domain, by integer id

func (*Client) DeleteDomainRecord

func (client *Client) DeleteDomainRecord(domainID int, recordType string, recordID int) error

DeleteDomainRecord delete one domain record

func (*Client) GetAllDomains

func (client *Client) GetAllDomains() ([]ConstellixDomain, error)

GetAllDomains get all domains on the acct

func (*Client) GetDomainByName

func (client *Client) GetDomainByName(name string) (ConstellixDomain, error)

GetDomainByName Get a single domain, by name

func (*Client) GetDomainID

func (client *Client) GetDomainID(name string) (int, error)

GetDomainID get domain id by name

func (*Client) GetDomainRecord

func (client *Client) GetDomainRecord(domainID int, recordType string, recordID int) (ConstellixRecord, error)

GetDomainRecord Get one record from a domain, by ID

func (*Client) GetDomainRecords

func (client *Client) GetDomainRecords(domainid int) ([]ConstellixRecord, error)

GetDomainRecords get all records for one domain by domain ID

func (*Client) GetRecordsByDomainName

func (client *Client) GetRecordsByDomainName(name string) ([]ConstellixRecord, error)

GetRecordsByDomainName get all records for a domain, by name

func (*Client) ListDomains

func (client *Client) ListDomains() ([]string, error)

ListDomains get a bare list of all domain names

func (*Client) ModifyDomain

func (client *Client) ModifyDomain(domain ConstellixDomain) error

ModifyDomain replace existing Domain

func (*Client) ModifyDomainRecord

func (client *Client) ModifyDomainRecord(domainID int, record ConstellixRecord) error

ModifyDomainRecord add a record to a domain

type ConstellixDomain

type ConstellixDomain struct {
	ID              int            `json:"id"`
	Name            string         `json:"name"`
	TypeID          int            `json:"typeId,omitempty"`
	HasGtdRegions   bool           `json:"hasGtdRegions,omitempty"`
	HasGeoIP        bool           `json:"hasGeoIP,omitempty"`
	NameserverGroup int            `json:"nameserverGroup,omitempty"`
	Nameservers     []string       `json:"nameservers,omitempty"`
	CreatedTs       time.Time      `json:"createdTs,omitempty"`
	ModifiedTs      time.Time      `json:"modifiedTs,omitempty"`
	Note            string         `json:"note,omitempty"`
	Version         int            `json:"version,omitempty"`
	Status          string         `json:"status,omitempty"`
	Tags            []string       `json:"tags,omitempty"`
	Soa             *ConstellixSoa `json:"soa,omitempty"`
}

ConstellixDomain holds a domain

type ConstellixRecord

type ConstellixRecord struct {
	ID                 int                     `json:"id"`
	Name               string                  `json:"name,omitempty"`
	TTL                int                     `json:"ttl,omitempty"`
	Geolocation        *GeolocationObj         `json:"geolocation,omitempty"`
	RecordOption       string                  `json:"recordOption,omitempty"`
	NoAnswer           bool                    `json:"noAnswer,omitempty"`
	Note               string                  `json:"note,omitempty"`
	GtdRegion          int                     `json:"gtdRegion,omitempty"`
	Type               string                  `json:"type,omitempty"`
	ParentID           int                     `json:"parentId,omitempty"`
	Parent             string                  `json:"parent,omitempty"`
	Source             string                  `json:"source,omitempty"`
	ContactIDs         []int                   `json:"contactIds,omitempty"`
	RoundRobin         []RoundRobinObj         `json:"roundRobin"`
	RecordFailover     *RecordFailoverObj      `json:"recordFailover,omitempty"`
	Pools              []int                   `json:"pools,omitempty"`
	RoundRobinFailover []RoundRobinFailoverObj `json:"roundRobinFailover,omitempty"`
	ModifiedTs         int                     `json:"modifiedTs,omitempty"`
	ModifiedTsDate     time.Time               `json:"modifiedTsDate,omitempty"`
	Createdts          time.Time               `json:"createdTs,omitempty"`
	RecordType         string                  `json:"recordType,omitempty"`
	Disabled           bool                    `json:"disabled"`
}

ConstellixRecord domain record

type ConstellixSoa

type ConstellixSoa struct {
	PrimaryNameserver string `json:"primaryNameserver,omitempty"`
	Email             string `json:"email,omitempty"`
	TTL               int    `json:"ttl,omitempty"`
	Serial            int    `json:"serial,omitempty"`
	Refresh           int    `json:"refresh,omitempty"`
	Retry             int    `json:"retry,omitempty"`
	Expire            int    `json:"expire,omitempty"`
	NegCache          int    `json:"negCache,omitempty"`
}

ConstellixSoa holds SOA records

type GeolocationObj

type GeolocationObj struct {
	GeoipUserRegion []int `json:"geoipUserRegion,omitempty"`
	Drop            bool  `json:"drop,omitempty"`
	GeoipFailover   bool  `json:"geoipFailover,omitempty"`
	GeoipProximity  int   `json:"geoipProximity,omitempty"`
}

GeolocationObj geolocation info

type RecordFailoverObj

type RecordFailoverObj struct {
	FailoverType    int                    `json:"failoverType"`
	Values          []RecordFailoverValues `json:"values"`
	SortOrder       int                    `json:"sortOrder,omitempty"`
	Failovertypestr string                 `json:"failoverTypeStr,omitempty"`
	FailedFlag      bool                   `json:"failedFlag,omitempty"`
	MarkedActive    bool                   `json:"markedActive,omitempty"`
	Disabled        bool                   `json:"disabled,omitempty"`
}

RecordFailoverObj Failover info

type RecordFailoverValues

type RecordFailoverValues struct {
	Value       string `json:"value"`
	CheckID     int    `json:"checkId"`
	DisableFlag bool   `json:"disableFlag"`
}

RecordFailoverValues Failover values

type RoundRobinFailoverObj

type RoundRobinFailoverObj struct {
	CheckID      int    `json:"checkId"`
	Value        string `json:"value"`
	DisableFlag  bool   `json:"disableFlag"`
	SortOrder    int    `json:"sortOrder,omitempty"`
	FailedFlag   bool   `json:"failedFlag,omitempty"`
	MarkedActive bool   `json:"markedActive,omitempty"`
}

RoundRobinFailoverObjValues RR Failover values

type RoundRobinObj

type RoundRobinObj struct {
	Value       string `json:"value"`
	Level       int    `json:"level,omitempty"` // for MX records
	DisableFlag bool   `json:"disableFlag"`
}

RoundRobinObj holds RoundRobin records from a domain

Jump to

Keyboard shortcuts

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