nameocean

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

NameOcean for libdns

Go Reference

This package implements the libdns interfaces for NameOcean DNS (ns1–ns4.nameocean.net), using NameOcean's API v1. It lets Go programs, such as Caddy, manage records in zones hosted at NameOcean, for example to solve ACME DNS-01 challenges.

Configuration

p := &nameocean.Provider{
	APIKey: "no_live_...", // or leave empty to use NAMEOCEAN_API_KEY
}
recs, err := p.GetRecords(ctx, "example.com.")
Field JSON Description
APIKey api_key A NameOcean API key with the dns:read and dns:write scopes. Create one in the dashboard under API. A key can be limited to the zones it should touch and to source IP addresses. Defaults to the NAMEOCEAN_API_KEY environment variable.
BaseURL base_url API address. Default https://nameocean.net/api/v1.
HTTPClient (none) HTTP client for API calls. Default: 30 second timeout.

The zone must be a DNS zone on the same NameOcean account.

Caveats

  • TTLs: NameOcean accepts 5m, 15m, 30m, 1h and 1d. Any other TTL is rounded to the closest of these (a tie goes to the shorter one); a zero TTL becomes 5m.
  • SetRecords is not atomic. NameOcean's per-record API has no batch call. SetRecords adds the new records first and deletes the old ones of the same (name, type) afterwards, so a name keeps answering during the change, but an error part-way can leave some changes made. Records that already match are left alone.
  • Record types: A, AAAA, CNAME, MX, TXT, SRV, CAA, NS, HTTPS and SVCB come back as the matching libdns structs; ALIAS (NameOcean's apex alias), PTR and DS as libdns.RR. NameOcean's HTTP redirect records are not DNS records and are not listed.
  • Targets are returned fully qualified with a trailing dot; a target that is the zone itself is stored as @ by NameOcean and returned as the zone's name.
  • Retries: GET and DELETE are retried twice on connection errors, 429 and 5xx; POST is not, so a record is never added twice.

Tests

go test ./... runs the unit tests against an in-memory fake of the API (it enforces the same uniqueness rules as NameOcean). To run against the real API (adds, changes and removes records under libdns-test and _acme-challenge.libdns-test, and checks the zone is as before):

NAMEOCEAN_API_KEY=... LIBDNS_NAMEOCEAN_TEST_ZONE=example.com. go test -run TestLive -v

The libdns test suite (libdnstest, libdns v1.2.0-alpha.1) passes ListZones, GetRecords, AppendRecords and DeleteRecords against a real zone, with every record type. Its SetRecords test fails only where it expects a 10 minute TTL back, because NameOcean rounds that to 5m.

Documentation

Overview

Package nameocean implements the libdns interfaces for NameOcean DNS (https://nameocean.net/dns/), through NameOcean's API v1 (https://nameocean.net/developers/api/).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// APIKey is a NameOcean API key with the dns:read and dns:write scopes
	// (Dashboard → API). It may be limited to the zones it should touch.
	// Defaults to the NAMEOCEAN_API_KEY environment variable.
	APIKey string `json:"api_key,omitempty"`

	// BaseURL overrides the API address. Default: https://nameocean.net/api/v1
	BaseURL string `json:"base_url,omitempty"`

	// HTTPClient is used for API calls. Default: a client with a 30 second timeout.
	HTTPClient *http.Client `json:"-"`
	// contains filtered or unexported fields
}

Provider manages records in NameOcean DNS zones. The zero value works when NAMEOCEAN_API_KEY is set in the environment.

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone and returns them as created. It never changes existing records.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records of the zone that match the input. The name is required; an empty type, a zero TTL or empty data match any value. Records that are not in the zone are ignored. It returns the records it deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone. NameOcean's HTTP redirect records are not DNS records and are left out.

func (*Provider) ListZones

func (p *Provider) ListZones(ctx context.Context) ([]libdns.Zone, error)

ListZones returns the zones the API key can see.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords makes the input records the only records of their (name, type) pairs in the zone. Records that already match are kept (a different TTL is changed in place); other records of the same (name, type) are changed in place to the remaining input records; what is still missing is added and what is left over is deleted. Other records are not touched.

It is not atomic: NameOcean's per-record API has no batch call, so an error part-way can leave some changes made. Deletions come last, so a name keeps answering during the change.

Jump to

Keyboard shortcuts

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