liara

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 11 Imported by: 0

README

Liara for libdns

Go Reference

This package implements the libdns interfaces for Liara, allowing you to manage DNS records.

How to configure

Simply, go to the Liara's console and obtain your API Key:

Image

Then, configure the provider:

	provider := &liara.Provider{
		APIToken: liaraAPIToken,
	}

	provider.DeleteRecords(ctx, "example.ir", records)

Documentation

Overview

Package liara implements a DNS record management client compatible with the libdns interfaces for Liara.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode    int    `json:"statusCode"`
	StatusMessage string `json:"error"`
	ErrorMessage  string `json:"message"`
}

The generic api error schema of Liara's dns api. E.x. StatusCode: 400 StatusMessage: "Bad Request" ErrorMessage: "invalid record type."

func (APIError) Error

func (e APIError) Error() string

type APIRecord

type APIRecord struct {
	// omitting the "id" field is a requirement in PUT operations.
	ID       string             `json:"id,omitempty"`
	Name     string             `json:"name"`
	Type     string             `json:"type"` // A, AAAA, CNAME, MX, SRV, TXT
	TTL      int                `json:"ttl"`
	Contents []APIRecordContent `json:"contents"`
}

func APIRecordContains

func APIRecordContains(records []APIRecord, target APIRecord) (*APIRecord, bool)

func ToLiaraAPIRecord

func ToLiaraAPIRecord(r libdns.Record, zone string) (APIRecord, error)

func ToLiaraAPIRecords

func ToLiaraAPIRecords(records []libdns.Record, zone string) ([]APIRecord, error)

turns a flat []libdns.Record into Liara's []APIRecord, where records with the same name + type can possibly share one APIRecord with multiple contents.

func (APIRecord) ToLibdnsRRType

func (r APIRecord) ToLibdnsRRType(zone string) ([]libdns.Record, error)

Converts the Liara specific "APIRecord" type to an appropriate, concrete RR type struct in libdns(the types are in the file "rrtypes.go").

It returns an slice(mostly a single item slice), because an APIRecord can consist of multiple "Contents" which doesn't fit into a single libdns type.

type APIRecordContent

type APIRecordContent struct {
	IP string `json:"ip,omitempty"`

	// Relevant to the CNAME record type
	Host string `json:"host,omitempty"`

	// Relevant to the MX And Srv record types.
	Priority uint16 `json:"priority,omitempty"`
	Weight   uint16 `json:"weight,omitempty"`
	Port     uint16 `json:"port,omitempty"`

	// Relevant to the TXT record types.
	Text string `json:"text,omitempty"`
}

func RemainingContent

func RemainingContent(
	existing []APIRecordContent,
	recordsToRemove []APIRecordContent,
) []APIRecordContent

Differentiates Remaining content in "APIRecord.Content". Takes the existing APIRecord.Contents and removes the contents that the user asked to delete.

type GetRecordsResponse

type GetRecordsResponse struct {
	Status string      `json:"status"`
	Data   []APIRecord `json:"data"`
}

type PostRecordResponse

type PostRecordResponse struct {
	Status string    `json:"status"`
	Data   APIRecord `json:"data"`
}

Liara's response model. The same model is also used for its PUT operation.

type Provider

type Provider struct {
	APIToken string `json:"api_token,omitempty"`
}

Provider facilitates DNS record manipulation with Liara

func (*Provider) AppendRecords

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

AppendRecords adds records to the zone. It returns the records that were added in a form of libdns concrete type, and not a opaque RR type.

func (*Provider) DeleteRecords

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

DeleteRecords deletes the specified records from the zone. It returns the records that were deleted.

func (*Provider) GetRecords

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

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

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

Here, the "SetRecords" method doesn't provide atomicity. Meaning a non nil value for the returned "error" can indicate that the zone is in a invalid state, and there is no rollback operation happened to rollback the previous changes.

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records, And not the skipped ones.

Jump to

Keyboard shortcuts

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