westcn

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 17 Imported by: 5

README

West.cn for libdns

Go Reference

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

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/libdns/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 struct {
	Result    int    `json:"result,omitempty"`
	ClientID  string `json:"clientid,omitempty"`
	Msg       string `json:"msg,omitempty"`
	ErrorCode int    `json:"errcode,omitempty"`
}

APIResponse API响应结构体 Result: 200为成功,其他均为失败 Msg: 错误或提示信息 https://www.west.cn/CustomerCenter/doc/apiv2.html#12u3001u8eabu4efdu9a8cu8bc10a3ca20id3d12u3001u8eabu4efdu9a8cu8bc13e203ca3e56

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client West.cn API 客户端

func NewClient

func NewClient(username, password string) *Client

NewClient 创建新 West.cn API 客户端

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"`
	// contains filtered or unexported fields
}

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. NOTE: This implementation is NOT atomic.

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. NOTE: This implementation is NOT atomic.

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. NOTE: This implementation is NOT atomic.

type Record

type Record struct {
	ID    int    `json:"id,omitempty"`
	Item  string `json:"item,omitempty"` // 主机名称,获取记录时返回
	Host  string `json:"host,omitempty"` // 主机名称,添加记录时需要
	Type  string `json:"type,omitempty"`
	Value string `json:"value,omitempty"`
	TTL   int    `json:"ttl,omitempty"` // 60~86400 seconds
	Level int    `json:"level,omitempty"`
}

type RecordID

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

type RecordIDResponse added in v1.0.0

type RecordIDResponse struct {
	APIResponse
	Data RecordID `json:"data,omitempty"`
}

type Records

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

type RecordsResponse added in v1.0.0

type RecordsResponse struct {
	APIResponse
	Data Records `json:"data,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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