From a742f096f08af9e015f44ea5354b8612091ed69e Mon Sep 17 00:00:00 2001 From: ZhuoQinghui <1302344380@qq.com> Date: Fri, 27 Dec 2024 17:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/acme-client.go | 1 - src/cmd/cmd.go | 39 +++++++++++++++++----------------- src/cmd/cmd_handle/cert.go | 22 +++++++++++++++++++ src/cmd/cmd_handle/conf.go | 19 +++++++++++++++++ src/cmd/cmd_handle/provider.go | 26 +++++++++++++++++++++++ src/cmd/cmd_handle/server.go | 32 +++++++++++++++++++++++----- src/cmd/cmd_handle/task.go | 26 +++++++++++++++++++++++ 7 files changed, 140 insertions(+), 25 deletions(-) delete mode 100644 src/acme-client.go create mode 100644 src/cmd/cmd_handle/cert.go create mode 100644 src/cmd/cmd_handle/conf.go create mode 100644 src/cmd/cmd_handle/provider.go create mode 100644 src/cmd/cmd_handle/task.go diff --git a/src/acme-client.go b/src/acme-client.go deleted file mode 100644 index c6d5f54..0000000 --- a/src/acme-client.go +++ /dev/null @@ -1 +0,0 @@ -package src diff --git a/src/cmd/cmd.go b/src/cmd/cmd.go index 73d2410..fa45b2b 100644 --- a/src/cmd/cmd.go +++ b/src/cmd/cmd.go @@ -1,6 +1,7 @@ package cmd import ( + "acme-mana/src/cmd/cmd_handle" "acme-mana/src/common" "acme-mana/src/conf" "github.com/spf13/cobra" @@ -52,7 +53,7 @@ func initConfCmd() *cobra.Command { Short: "查看配置列表", Long: "查看系统配置列表", Run: func(cmd *cobra.Command, args []string) { - confShow(cmd, args) + cmd_handle.ConfShow(cmd, args) }, } confCmd.AddCommand(confShow) @@ -76,7 +77,7 @@ func initServerCmd() *cobra.Command { Short: "编辑服务配置", Long: "编辑服务配置", Run: func(cmd *cobra.Command, args []string) { - editServer(cmd, args) + cmd_handle.ServerEdit(cmd, args) }, } stateCmd := &cobra.Command{ @@ -84,7 +85,7 @@ func initServerCmd() *cobra.Command { Short: "查看服务状态", Long: "查看服务状态", Run: func(cmd *cobra.Command, args []string) { - serverState(cmd, args) + cmd_handle.ServerState(cmd, args) }, } startCmd := &cobra.Command{ @@ -92,7 +93,7 @@ func initServerCmd() *cobra.Command { Short: "启动服务", Long: "启动服务", Run: func(cmd *cobra.Command, args []string) { - startServer(cmd, args) + cmd_handle.ServerStart(cmd, args) }, } stopCmd := &cobra.Command{ @@ -100,7 +101,7 @@ func initServerCmd() *cobra.Command { Short: "停止服务", Long: "停止服务", Run: func(cmd *cobra.Command, args []string) { - stopServer(cmd, args) + cmd_handle.ServerStop(cmd, args) }, } @@ -125,7 +126,7 @@ func initTaskCmd() *cobra.Command { Short: "编辑定时任务配置", Long: "编辑定时任务配置", Run: func(cmd *cobra.Command, args []string) { - editTask(cmd, args) + cmd_handle.TaskEdit(cmd, args) }, } startTask := &cobra.Command{ @@ -133,7 +134,7 @@ func initTaskCmd() *cobra.Command { Short: "启动定时任务", Long: "启动定时任务", Run: func(cmd *cobra.Command, args []string) { - startTask(cmd, args) + cmd_handle.TaskStart(cmd, args) }, } stopTask := &cobra.Command{ @@ -141,7 +142,7 @@ func initTaskCmd() *cobra.Command { Short: "停止定时任务", Long: "停止定时任务", Run: func(cmd *cobra.Command, args []string) { - stopTask(cmd, args) + cmd_handle.TaskStop(cmd, args) }, } statusTask := &cobra.Command{ @@ -149,7 +150,7 @@ func initTaskCmd() *cobra.Command { Short: "查看定时任务状态", Long: "查看定时任务状态", Run: func(cmd *cobra.Command, args []string) { - statusTask(cmd, args) + cmd_handle.TaskStatus(cmd, args) }, } runTask := &cobra.Command{ @@ -157,7 +158,7 @@ func initTaskCmd() *cobra.Command { Short: "手动执行一次任务", Long: "手动执行一次任务", Run: func(cmd *cobra.Command, args []string) { - runTask(cmd, args) + cmd_handle.TaskRun(cmd, args) }, } taskCmd.AddCommand(editTask) @@ -182,7 +183,7 @@ func initProviderCmd() *cobra.Command { Short: "列出支持的DNS服务商", Long: "列出支持的DNS服务商", Run: func(cmd *cobra.Command, args []string) { - providerSupport(cmd, args) + cmd_handle.ProviderSupport(cmd, args) }, } providerList := &cobra.Command{ @@ -190,7 +191,7 @@ func initProviderCmd() *cobra.Command { Short: "列出已配置的DNS服务商", Long: "列出已配置的DNS服务商", Run: func(cmd *cobra.Command, args []string) { - providerList(cmd, args) + cmd_handle.ProviderList(cmd, args) }, } providerAdd := &cobra.Command{ @@ -198,7 +199,7 @@ func initProviderCmd() *cobra.Command { Short: "添加DNS服务商", Long: "添加DNS服务商", Run: func(cmd *cobra.Command, args []string) { - providerAdd(cmd, args) + cmd_handle.ProviderAdd(cmd, args) }, } providerEdit := &cobra.Command{ @@ -206,7 +207,7 @@ func initProviderCmd() *cobra.Command { Short: "编辑DNS服务商", Long: "编辑DNS服务商", Run: func(cmd *cobra.Command, args []string) { - providerEdit(cmd, args) + cmd_handle.ProviderEdit(cmd, args) }, } providerDelete := &cobra.Command{ @@ -214,7 +215,7 @@ func initProviderCmd() *cobra.Command { Short: "删除DNS服务商", Long: "删除DNS服务商", Run: func(cmd *cobra.Command, args []string) { - providerDelete(cmd, args) + cmd_handle.ProviderDelete(cmd, args) }, } @@ -240,7 +241,7 @@ func certCmd() *cobra.Command { Short: "列出已配置的证书", Long: "列出已配置的证书", Run: func(cmd *cobra.Command, args []string) { - certList(cmd, args) + cmd_handle.CertList(cmd, args) }, } certAdd := &cobra.Command{ @@ -248,7 +249,7 @@ func certCmd() *cobra.Command { Short: "添加证书", Long: "添加证书", Run: func(cmd *cobra.Command, args []string) { - certAdd(cmd, args) + cmd_handle.CertAdd(cmd, args) }, } certDelete := &cobra.Command{ @@ -256,7 +257,7 @@ func certCmd() *cobra.Command { Short: "删除证书", Long: "删除证书", Run: func(cmd *cobra.Command, args []string) { - certDelete(cmd, args) + cmd_handle.CertDelete(cmd, args) }, } editCert := &cobra.Command{ @@ -264,7 +265,7 @@ func certCmd() *cobra.Command { Short: "编辑证书", Long: "编辑证书", Run: func(cmd *cobra.Command, args []string) { - editCert(cmd, args) + cmd_handle.CertEdit(cmd, args) }, } certCmd.AddCommand(certList) diff --git a/src/cmd/cmd_handle/cert.go b/src/cmd/cmd_handle/cert.go new file mode 100644 index 0000000..0c68e93 --- /dev/null +++ b/src/cmd/cmd_handle/cert.go @@ -0,0 +1,22 @@ +package cmd_handle + +import ( + "fmt" + "github.com/spf13/cobra" +) + +func CertEdit(cmd *cobra.Command, args []string) { + fmt.Println("edit cert") +} + +func CertDelete(cmd *cobra.Command, args []string) { + fmt.Println("delete cert") +} + +func CertAdd(cmd *cobra.Command, args []string) { + fmt.Println("add cert") +} + +func CertList(cmd *cobra.Command, args []string) { + fmt.Println("list cert") +} diff --git a/src/cmd/cmd_handle/conf.go b/src/cmd/cmd_handle/conf.go new file mode 100644 index 0000000..2f4e913 --- /dev/null +++ b/src/cmd/cmd_handle/conf.go @@ -0,0 +1,19 @@ +package cmd_handle + +import ( + "acme-mana/src/conf" + "encoding/json" + "fmt" + tea "github.com/charmbracelet/bubbletea" + "github.com/spf13/cobra" +) + +// ConfShow 打印 配置信息 +func ConfShow(cmd *cobra.Command, args []string) { + tea.Println() + confJson, err := json.MarshalIndent(conf.Config(), "", " ") + if err != nil { + fmt.Println("序列化配置信息失败:", err) + } + fmt.Println(string(confJson)) +} diff --git a/src/cmd/cmd_handle/provider.go b/src/cmd/cmd_handle/provider.go new file mode 100644 index 0000000..9dbe016 --- /dev/null +++ b/src/cmd/cmd_handle/provider.go @@ -0,0 +1,26 @@ +package cmd_handle + +import ( + "fmt" + "github.com/spf13/cobra" +) + +func ProviderDelete(cmd *cobra.Command, args []string) { + fmt.Println("delete provider") +} + +func ProviderEdit(cmd *cobra.Command, args []string) { + fmt.Println("edit provider") +} + +func ProviderAdd(cmd *cobra.Command, args []string) { + fmt.Println("add provider") +} + +func ProviderList(cmd *cobra.Command, args []string) { + fmt.Println("list provider") +} + +func ProviderSupport(cmd *cobra.Command, args []string) { + fmt.Println("support provider") +} diff --git a/src/cmd/cmd_handle/server.go b/src/cmd/cmd_handle/server.go index 053726b..2d77523 100644 --- a/src/cmd/cmd_handle/server.go +++ b/src/cmd/cmd_handle/server.go @@ -2,7 +2,11 @@ package cmd_handle import ( "acme-mana/src/common" + "acme-mana/src/conf" "acme-mana/src/server" + "acme-mana/src/util" + "fmt" + "github.com/spf13/cobra" "log" "os" "os/exec" @@ -15,20 +19,22 @@ import ( var stdout *os.File var stderr *os.File -func start() { +func ServerStart(command *cobra.Command, args []string) { initLog() isDaemon := os.Getenv("GO_DAEMON") log.Println("守护进程启动: " + isDaemon) - if isDaemon != "1" { - daemonStart() - return - } if isRunning() { log.Println("守护进程已启动, 跳过执行") return } + + if isDaemon == "1" { + daemonStart() + return + } + workPath, err := os.Executable() if err != nil { log.Fatalf("无法获取当前工作路径: %v", err) @@ -56,6 +62,22 @@ func start() { os.Exit(0) } +func ServerEdit(cmd *cobra.Command, args []string) { + s := conf.Config().Server + host := util.ReadLine("请输入服务监听地址;", s.Host) + port := util.ReadInt("请输入服务监听端口;", strconv.Itoa(s.Port)) + key := util.ReadLine("请输入服务通信认证秘钥;", s.Key) + conf.EditServer(host, port, key) + fmt.Println("服务监听配置已完成") +} + +func ServerState(cmd *cobra.Command, args []string) { + server.HttpInstance.Status() +} +func ServerStop(cmd *cobra.Command, args []string) { + server.HttpInstance.Stop() +} + func daemonStart() { // 启动 HttpServer server.HttpInstance.Init() diff --git a/src/cmd/cmd_handle/task.go b/src/cmd/cmd_handle/task.go new file mode 100644 index 0000000..ca826b7 --- /dev/null +++ b/src/cmd/cmd_handle/task.go @@ -0,0 +1,26 @@ +package cmd_handle + +import ( + "fmt" + "github.com/spf13/cobra" +) + +func TaskEdit(cmd *cobra.Command, args []string) { + fmt.Println("edit task") +} + +func TaskStatus(cmd *cobra.Command, args []string) { + fmt.Println("status task") +} + +func TaskStop(cmd *cobra.Command, args []string) { + fmt.Println("stop task") +} + +func TaskStart(cmd *cobra.Command, args []string) { + fmt.Println("start task") +} + +func TaskRun(cmd *cobra.Command, args []string) { + fmt.Println("run task") +}