3个版本
0.1.2 | 2023年3月20日 |
---|---|
0.1.1 | 2023年3月16日 |
0.1.0 | 2023年3月16日 |
#12 in #阿里云
26KB
246 行
阿里云DNS API客户端
此库提供了一个简单易用的客户端,用于与阿里云DNS API交互。使用此库,您可以以编程方式管理您的域名记录,包括添加、更新、删除和查询记录。
用法
要使用此库,首先创建一个新的 AliyunDns
实例,提供您的 access_key_id
和 access_key_secret
use aliyun_dns::AliyunDns;
let access_key_id = "your_access_key_id";
let access_key_secret = "your_access_key_secret";
let aliyun_dns = AliyunDns::new(access_key_id.to_string(), access_key_secret.to_string());
添加域名记录
要添加域名记录,请使用 add_domain_record
方法
let domain_name = "example.com";
let sub_domain = "www";
let record_type = "A";
let record_value = "1.2.3.4";
let response = aliyun_dns.add_domain_record(domain_name, sub_domain, record_type, record_value).await?;
println!("Record ID: {}", response.record_id);
更新域名记录
要更新域名记录,请使用 update_domain_record
方法
let record_id = "your_record_id";
let sub_domain = "www";
let record_type = "A";
let new_value = "2.3.4.5";
let response = aliyun_dns.update_domain_record(record_id, sub_domain, record_type, new_value).await?;
println!("Updated Record ID: {}", response.record_id);
删除域名记录
要删除域名记录,请使用 delete_domain_record
方法
let record_id = "your_record_id";
let response = aliyun_dns.delete_domain_record(record_id).await?;
println!("Deleted Record ID: {}", response.record_id);
删除子域名记录
要删除子域名记录,请使用 delete_subdomain_records
方法
let domain_name = "example.com";
let rr = "www";
let response = aliyun_dns.delete_subdomain_records(domain_name, rr).await?;
println!("Deleted RR: {}, Total Count: {}", response.rr, response.total_count);
查询域名记录
要查询域名记录,请使用 query_domain_records
方法
let domain_name = "example.com";
let response = aliyun_dns.query_domain_records(domain_name).await?;
println!("Total Records: {}", response.total_count);
for record in response.domain_records.records {
println!(
"Record ID: {}, Type: {}, RR: {}, Value: {}",
record.record_id, record.record_type, record.rr, record.value
);
}
示例程序
以下是一个示例程序,演示如何使用AliyunDns客户端
use aliyun_dns::AliyunDns;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
let access_key_id = "your_access_key_id";
let access_key_secret = "your_access_key_secret";
let aliyun_dns = AliyunDns::new(access_key_id.to_string(), access_key_secret.to_string());
// Add a domain record
let domain_name = "example.com";
let sub_domain = "www";
let record_type = "A";
let record_value = "1.2.3.4";
let response = aliyun_dns.add_domain_record(domain_name, sub_domain, record_type, record_value).await?;
println!("Record ID: {}", response.record_id);
// Update a domain record
let record_id = &response.record_id;
let sub_domain = "www";
let record_type = "A";
let new_value = "2.3.4.5";
let update_response = aliyun_dns.update_domain_record(record_id, sub_domain, record_type, new_value).await?;
println!("Updated Record ID: {}", update_response.record_id);
// Query domain records
let query_response = aliyun_dns.query_domain_records(domain_name).await?;
println!("Total Records: {}", query_response.total_count);
for record in query_response.domain_records.records {
println!(
"Record ID: {}, Type: {}, RR: {}, Value: {}",
record.record_id, record.record_type, record.rr, record.value
);
}
// Delete a domain record
let delete_response = aliyun_dns.delete_domain_record(record_id).await?;
println!("Deleted Record ID: {}", delete_response.record_id);
// Delete subdomain records
let rr = "www";
let delete_subdomain_response = aliyun_dns.delete_subdomain_records(domain_name, rr).await?;
println!(
"Deleted RR: {}, Total Count: {}",
delete_subdomain_response.rr, delete_subdomain_response.total_count
);
Ok(())
}
依赖项
~7–20MB
~303K SLoC