From c14c6dacffcb7414b1373f3822bcccf01423f52d Mon Sep 17 00:00:00 2001 From: dean Date: Thu, 6 Nov 2025 09:40:56 +0800 Subject: [PATCH 1/2] add dns txt --- Makefile | 3 +- cmd/{host.go => dns_host.go} | 0 cmd/{service.go => dns_srv.go} | 4 ++ cmd/dns_txt.go | 82 ++++++++++++++++++++++++++++++++++ cmd/root.go | 1 + 5 files changed, 89 insertions(+), 1 deletion(-) rename cmd/{host.go => dns_host.go} (100%) rename cmd/{service.go => dns_srv.go} (99%) create mode 100644 cmd/dns_txt.go diff --git a/Makefile b/Makefile index fc4a8da..92d368a 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ test: go test -v ./... dev: - CGO_ENABLED=0 $(SYSTEM) GOARCH=amd64 go run $(LDFLAGS) main.go + #CGO_ENABLED=0 $(SYSTEM) GOARCH=amd64 go run $(LDFLAGS) main.go + CGO_ENABLED=0 $(SYSTEM) go build $(LDFLAGS) main.go build: @bash ./build/util.sh until::build diff --git a/cmd/host.go b/cmd/dns_host.go similarity index 100% rename from cmd/host.go rename to cmd/dns_host.go diff --git a/cmd/service.go b/cmd/dns_srv.go similarity index 99% rename from cmd/service.go rename to cmd/dns_srv.go index 9b2703e..233feeb 100644 --- a/cmd/service.go +++ b/cmd/dns_srv.go @@ -79,6 +79,10 @@ func service() { } for _, rr := range output.DomainRecords.Record { + if rr.Type != "SRV" { + continue + } + if rr.RR == typeutil.DelimiterStar || rr.RR == typeutil.DelimiterAt { continue } diff --git a/cmd/dns_txt.go b/cmd/dns_txt.go new file mode 100644 index 0000000..1495dd0 --- /dev/null +++ b/cmd/dns_txt.go @@ -0,0 +1,82 @@ +/* +Copyright © 2020 NAME HERE + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + + "github.com/airdb/toolbox/typeutil" + "github.com/aliyun/alibaba-cloud-sdk-go/services/alidns" + "github.com/spf13/cobra" +) + +// dnsTxtCmd represents the service command. +var dnsTxtCmd = &cobra.Command{ + Use: "txt", + Short: "Airdb dns txt client", + Long: `Airdb dns txt client`, + Aliases: []string{"service", "services"}, + Run: func(cmd *cobra.Command, args []string) { + dnsTxt() + }, +} + +func dnsTxtCmdInit() { + rootCmd.AddCommand(dnsTxtCmd) + /* + dnsTxtCmd.AddCommand(servicesAddCmd) + dnsTxtCmd.AddCommand(servicesUpdateCmd) + dnsTxtCmd.AddCommand(servicesDeleteCmd) + + dnsTxtCmd.PersistentFlags().BoolVarP(&serviceFlags.List, "list", "l", false, "list all services") + servicesUpdateCmd.PersistentFlags().StringVarP(&updateDNSFlag.RecordID, + "id", "i", "", "srv record_id") + servicesUpdateCmd.PersistentFlags().StringVarP(&updateDNSFlag.Remark, + "remark", "m", "", "srv remark or comment") + */ +} + +type dnsTxtStruct struct { + List bool +} + +func dnsTxt() { + client, err := aliyunConfigInit() + if err != nil { + panic(err) + } + + request := alidns.CreateDescribeDomainRecordsRequest() + request.DomainName = ServiceDomain + + output, err := client.DescribeDomainRecords(request) + if err != nil { + fmt.Println(err) + } + + for _, rr := range output.DomainRecords.Record { + if rr.Type != "TXT" { + continue + } + + if rr.RR == typeutil.DelimiterStar || rr.RR == typeutil.DelimiterAt { + continue + } + + // fmt.Printf("%-20s\t%-32s\t%s\n", rr.RecordId, rr.RR, rr.Value) + fmt.Printf("%-20s %-32s %-64s %s\n", rr.RecordId, rr.RR, rr.Value, rr.Remark) + } +} diff --git a/cmd/root.go b/cmd/root.go index 850951d..f9f9455 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,6 +29,7 @@ func Execute() { mysqlCmdInit() serviceCmdInit() + dnsTxtCmdInit() hostCmdInit() // initConfigCmd() From 5b620be1ebe256fb6fcd41fe87cc3a15047b7123 Mon Sep 17 00:00:00 2001 From: dean Date: Thu, 6 Nov 2025 12:12:23 +0800 Subject: [PATCH 2/2] chore: change order --- cmd/dns_srv.go | 2 +- cmd/dns_txt.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/dns_srv.go b/cmd/dns_srv.go index 233feeb..a013dff 100644 --- a/cmd/dns_srv.go +++ b/cmd/dns_srv.go @@ -88,7 +88,7 @@ func service() { } // fmt.Printf("%-20s\t%-32s\t%s\n", rr.RecordId, rr.RR, rr.Value) - fmt.Printf("%-20s %-32s %-64s %s\n", rr.RecordId, rr.RR, rr.Value, rr.Remark) + fmt.Printf("%-20s %32s %-64s %s\n", rr.RecordId, rr.RR, rr.Value, rr.Remark) } } diff --git a/cmd/dns_txt.go b/cmd/dns_txt.go index 1495dd0..8bdc71f 100644 --- a/cmd/dns_txt.go +++ b/cmd/dns_txt.go @@ -77,6 +77,6 @@ func dnsTxt() { } // fmt.Printf("%-20s\t%-32s\t%s\n", rr.RecordId, rr.RR, rr.Value) - fmt.Printf("%-20s %-32s %-64s %s\n", rr.RecordId, rr.RR, rr.Value, rr.Remark) + fmt.Printf("%-20s %32s %-64s %s\n", rr.RecordId, rr.RR, rr.Value, rr.Remark) } }