mijnhost

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 9 Imported by: 4 modules, 3 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

Mijn Host for libdns

This package implements the libdns interfaces for the Mijn Host API

Authenticating

To authenticate, you need to create an api key here.

Example

Here's a minimal example of how to get all your DNS records using this libdns provider

package main

import (
	"context"
	"fmt"
	"os"
	"text/tabwriter"
	
	"github.com/pbergman/provider"
	"github.com/libdns/mijnhost"
)

func main() { 
	var p = &mijnhost.Provider{
		ApiKey: "***************************",
    }

	zones, err := p.ListZones(context.Background())

	if err != nil {
		panic(err)
	}

	var writer = tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)

	for _, zone := range zones {
		records, err := p.GetRecords(context.Background(), zone.Name)

		if err != nil {
			panic(err)
		}

		for _, record := range provider.RecordIterator(&records) {
			_, _ = fmt.Fprintf(writer, "%s\t%v\t%s\t%s\n", record.Name, record.TTL.Seconds(), record.Type, record.Data)
		}

	}

	_ = writer.Flush()
}

Debugging

This library provides the ability to debug the request/response communication with the API server.

To enable debugging, simply set the debugging property to true:

	var provider = &mijnhost.Provider{
		ApiKey: "***************************",
		DebugLevel: provider.OutputDebug,
    }

	zones, err := provider.ListZones(context.Background())

	if err != nil {
		panic(err)
	}

	records, err := provider.GetRecords(context.Background(), "example.nl")
........................
[c] GET /api/v2/domains/example.nl/dns HTTP/1.1
[c] Host: mijn.host
[c] Accept: application/json
[c] Api-Key: ***************************
[c] Content-Type: application/json
[c] User-Agent: libdns-client/1.0
[c] 
[s] HTTP/2.0 200 OK
[s] Connection: close
[s] Content-Security-Policy: frame-ancestors 'self';
[s] Content-Type: application/json
[s] Date: Wed, 24 Sep 2025 08:46:46 GMT
[s] Feature-Policy: autoplay 'none'; camera 'none'; encrypted-media 'self'; fullscreen 'self'; geolocation 'none'; microphone 'none'; midi 'none'; payment 'none'; vr 'none'
[s] Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(self), battery=(), camera=(), cross-origin-isolated=(self), display-capture=(self), document-domain=(self), encrypted-media=(self), execution-while-not-rendered=(self), execution-while-out-of-viewport=(self), fullscreen=(self), geolocation=(self), gyroscope=(), keyboard-map=(self), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(self), picture-in-picture=(self), publickey-credentials-get=(self), screen-wake-lock=(), sync-xhr=(self), usb=(), web-share=(self), xr-spatial-tracking=(self), clipboard-read=(), clipboard-write=(self), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), unload=(), window-placement=(), vertical-scroll=()
[s] Referrer-Policy: strict-origin-when-cross-origin
[s] Server: Apache/2
[s] Strict-Transport-Security: max-age=31536000
[s] Vary: User-Agent
[s] X-Content-Type-Options: nosniff
[s] X-Frame-Options: SAMEORIGIN
[s] X-Xss-Protection: 1; mode=block
[s] 
[s] {"status":200,"status_description":"Request successful","data":{"domain":"example.nl","records":.....

This will by default write to stdout but can set to any io.Writer by also setting the DebugOut property.

    var provider = &mijnhost.Provider{
        ApiKey: "***************************",
        DebugLevel: provider.OutputDebug,
        DebugOut: log.Writer(),
    }

Testing

This library comes with a test suite that verifies the interface by creating a few test records, validating them, and then removing those records. To run the tests, you can use:

API_KEY=<MIJN_HOST_KEY> go test

Or run more verbose test to dump all api requests and responses:

API_KEY=<MIJN_HOST_KEY> DEBUG=1 go test -v 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiBaseUri added in v1.0.0

type ApiBaseUri url.URL

func DefaultApiBaseUri added in v1.0.0

func DefaultApiBaseUri() *ApiBaseUri

func (*ApiBaseUri) MarshalJSON added in v1.0.0

func (a *ApiBaseUri) MarshalJSON() ([]byte, error)

func (*ApiBaseUri) UnmarshalJSON added in v1.0.0

func (a *ApiBaseUri) UnmarshalJSON(data []byte) error

type Client added in v1.0.0

type Client interface {
	provider.Client
	provider.ZoneAwareClient
}

type Provider

type Provider struct {
	// ApiKey used for authenticating the mijn.host api see:
	// https://mijn.host/api/doc/doc-343216#obtaining-your-api-key
	ApiKey string `json:"api_key"`
	// BaseUri used for the api calls and will default to https://mijn.host/api/v2/
	BaseUri *ApiBaseUri `json:"base_uri"`

	// DebugLevel sets the verbosity for logging API requests and responses.
	DebugLevel provider.OutputLevel `json:"debug_level"`
	// DebugOut defines the output destination for debug logs.
	// Defaults to standard output (STDOUT).
	DebugOut io.Writer `json:"-"`
	// contains filtered or unexported fields
}

func (*Provider) AppendRecords

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

func (*Provider) DebugOutput added in v1.1.0

func (p *Provider) DebugOutput() io.Writer

func (*Provider) DebugOutputLevel added in v1.1.0

func (p *Provider) DebugOutputLevel() provider.OutputLevel

func (*Provider) DeleteRecords

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

func (*Provider) GetApiKey added in v1.0.0

func (p *Provider) GetApiKey() string

func (*Provider) GetBaseUri added in v1.0.0

func (p *Provider) GetBaseUri() *url.URL

func (*Provider) GetRecords

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

func (*Provider) ListZones added in v1.0.0

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

func (*Provider) SetDebug added in v1.1.0

func (p *Provider) SetDebug(level provider.OutputLevel, writer io.Writer)

func (*Provider) SetRecords

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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