westcn

package module
v0.0.0-...-b493758 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 18 Imported by: 1

README

West.cn for libdns

Go Reference

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

This package references and uses the implementation of lego.

Authenticating

To authenticate you need to supply your Username and APIPassword to the Provider.

Example

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

package main

import (
	"context"
	"fmt"

	"github.com/devhaozi/westcn"
)

func main() {
	provider := westcn.Provider{
		Username: "<Username form your west.cn account>",
		APIPassword: "<APIPassword form your west.cn account>",
	}

	records, err  := provider.GetRecords(context.TODO(), "example.com.")
	if err != nil {
		fmt.Println(err.Error())
	}

	for _, record := range records {
		fmt.Printf("%s %v %s %s\n", record.Name, record.TTL.Seconds(), record.Type, record.Value)
	}
}

For complete demo check _example/main.go

Documentation

Overview

Package westcn implements a DNS record management client compatible with the libdns interfaces for west.cn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse[T any] struct {
	Result    int    `json:"result,omitempty"`
	ClientID  string `json:"clientid,omitempty"`
	Message   string `json:"msg,omitempty"`
	ErrorCode int    `json:"errcode,omitempty"`
	Data      T      `json:"data,omitempty"`
}

func (APIResponse[T]) Error

func (a APIResponse[T]) Error() string

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client the West.cn API client.

func NewClient

func NewClient(username, password string) (*Client, error)

NewClient creates a new Client.

type Item

type Item struct {
	ID    int    `json:"id,omitempty"`
	Host  string `json:"item,omitempty"`
	Type  string `json:"type,omitempty"`
	Value string `json:"value,omitempty"`
	TTL   int    `json:"ttl,omitempty"`
	Level int    `json:"level,omitempty"`
}

type Provider

type Provider struct {
	// Username is your username for west.cn, see https://www.west.cn/CustomerCenter/doc/apiv2.html#12u3001u8eabu4efdu9a8cu8bc10a3ca20id3d12u3001u8eabu4efdu9a8cu8bc13e203ca3e
	Username string `json:"username,omitempty"`
	// APIPassword is your API password for west.cn, see https://www.west.cn/CustomerCenter/doc/apiv2.html#12u3001u8eabu4efdu9a8cu8bc10a3ca20id3d12u3001u8eabu4efdu9a8cu8bc13e203ca3e
	APIPassword string `json:"api_password,omitempty"`
}

Provider facilitates DNS record manipulation with west.cn.

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.

func (*Provider) DeleteRecords

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

DeleteRecords deletes the 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)

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

type Record

type Record struct {
	Domain string `url:"domain,omitempty"`
	Host   string `url:"host,omitempty"`
	Type   string `url:"type,omitempty"`
	Value  string `url:"value,omitempty"`
	TTL    int    `url:"ttl,omitempty"` // 60~86400 seconds
	Level  int    `url:"level,omitempty"`
}

type RecordID

type RecordID struct {
	ID int `json:"id,omitempty"`
}

type Records

type Records struct {
	Items []Item `json:"items,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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