gonjalla

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: MIT Imports: 6 Imported by: 0

README

Unofficial Golang library for the Njalla API

Njalla is a privacy-oriented domain name registration service. Recently they released their official API.

This Golang library covers some methods of that API. For the moment, those are:

  • list-domains
  • get-domain
  • list-records
  • add-record
  • edit-record
  • remove-record

TO NOTE: Even though record methods are implemented, I'm fairly certain they'll fail (silently or not) in some cases. I deal mostly with TXT, MX, A and AAAA DNS records. Some records have different/more variables, and since I don't use them I decided against implementing them. Chances are the methods will fail when trying to deal with those types of records (like SSH records).

The code is fairly simple, and all the methods are tested by using mocks on the API request. The mocked returned data is based on the same data the API returns.

These methods cover my needs, but feel free to send in a PR to add more (or to cover all types of DNS records), as long as they're all tested and documented.

Usage
package main

import (
	"fmt"

	"github.com/Sighery/gonjalla"
)

func main() {
	token := "api-token"
	domain := "your-domain"

	records, err := ListRecords(token, domain)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(records)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidPriority = []int{0, 1, 5, 10, 20, 30, 40, 50, 60}

ValidPriority is an array containing all the valid Priority values

View Source
var ValidTTL = []int{60, 300, 900, 3600, 10800, 21600, 86400}

ValidTTL is an array containing all the valid TTL values

Functions

func EditRecord

func EditRecord(token string, domain string, record Record) error

EditRecord edits a record for a given domain. This function is fairly dumb. It takes in a `Record` struct, and uses all its filled fields to send to Njalla. So, if you want to only change a given field, get the `Record` object from say ListRecords, change the one field you want, and then pass that here.

func RemoveRecord

func RemoveRecord(token string, domain string, id int) error

RemoveRecord removes a given record from a given domain. If there are no errors it will return `nil`.

func Request

func Request(token string, method string, params map[string]interface{}) ([]byte, error)

Request common function for all of Njalla's API. Njalla's API uses JSON-RPC, and contains just one endpoint. The endpoint is POST only, and takes in a JSON in the body, with two arguments, check the `request` struct for more info. The `params` argument is variable. Some methods require no parameters, (like `list-domains`), while other methods require parameters (like `get-domain` which requires `domain: string`).

Types

type Domain

type Domain struct {
	Name           string    `json:"name"`
	Status         string    `json:"status"`
	Expiry         time.Time `json:"expiry"`
	Locked         *bool     `json:"locked,omitempty"`
	Mailforwarding *bool     `json:"mailforwarding,omitempty"`
	MaxNameservers *int      `json:"max_nameservers,omitempty"`
}

Domain struct contains data returned by `list-domains` and `get-domains`

func GetDomain

func GetDomain(token string, domain string) (Domain, error)

GetDomain returns detailed information for each domain

func ListDomains

func ListDomains(token string) ([]Domain, error)

ListDomains returns a listing of domains with minimal data

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient interface. Useful for mocked unit tests later on.

var (
	// Client used in all requests by Request. Can be overwritten for tests.
	Client HTTPClient
)

type MarketDomain

type MarketDomain struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Price  int    `json:"price"`
}

func FindDomains

func FindDomains(token string, query string) ([]MarketDomain, error)

type Record

type Record struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Type     string `json:"type"`
	Content  string `json:"content"`
	TTL      int    `json:"ttl"`
	Priority *int   `json:"prio,omitempty"`
}

Record struct contains data returned by `list-records`

func AddRecord

func AddRecord(token string, domain string, record Record) (Record, error)

AddRecord adds a given record to a given domain. Returns a new Record struct, containing the response from the API if successful. This response will have some fields like ID (which can only be known after the execution) filled.

func ListRecords

func ListRecords(token string, domain string) ([]Record, error)

ListRecords returns a listing of all records for a given domain

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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