Files
晴天 e161574dfb fix: 修复 6 个 issue — ingress 同步/日志跨平台/Windows 优雅停止/多级 TLD
- #1 add 命令添加路由后自动推送 ingress 配置到 Cloudflare
- #2 logs 命令支持 macOS/Windows/Linux 日志路径
- #3 remove 命令删除路由后同步 ingress 配置
- #4 logs 命令使用纯 Go 实现 tail,移除 Unix tail 依赖
- #5 Windows 使用 taskkill 优雅停止 cloudflared(替代 Kill)
- #6 add 命令域名解析支持多级 TLD(.co.uk/.com.cn 等)
2026-02-23 11:27:57 +08:00

57 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cmd
import (
"context"
"fmt"
"github.com/qingchencloud/cftunnel/internal/cfapi"
"github.com/qingchencloud/cftunnel/internal/config"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(removeCmd)
}
var removeCmd = &cobra.Command{
Use: "remove <名称>",
Short: "删除路由(清理 DNS + ingress",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
cfg, err := config.Load()
if err != nil {
return err
}
route := cfg.FindRoute(name)
if route == nil {
return fmt.Errorf("路由 %s 不存在", name)
}
client := cfapi.New(cfg.Auth.APIToken, cfg.Auth.AccountID)
ctx := context.Background()
// 删除 DNS 记录
if route.DNSRecordID != "" && route.ZoneID != "" {
fmt.Printf("正在删除 DNS 记录 %s...\n", route.Hostname)
if err := client.DeleteDNSRecord(ctx, route.ZoneID, route.DNSRecordID); err != nil {
fmt.Printf("警告: 删除 DNS 记录失败: %v\n", err)
}
}
cfg.RemoveRoute(name)
if err := cfg.Save(); err != nil {
return err
}
// 推送 ingress 配置到远端
fmt.Println("正在同步 ingress 配置...")
if err := pushIngress(client, ctx, cfg); err != nil {
fmt.Printf("警告: 推送 ingress 失败: %v\n", err)
}
fmt.Printf("路由 %s 已删除\n", name)
return nil
},
}