This commit is contained in:
ZhuoQinghui 2024-11-01 17:45:48 +08:00
parent 30d77aac56
commit 55d241b873
9 changed files with 164 additions and 3 deletions

6
go.mod
View File

@ -8,7 +8,9 @@ require (
github.com/charmbracelet/bubbletea v1.1.2
github.com/gin-gonic/gin v1.10.0
github.com/go-acme/lego/v4 v4.19.1
github.com/manifoldco/promptui v0.9.0
github.com/spf13/cobra v1.8.1
github.com/urfave/cli/v2 v2.27.4
gopkg.in/yaml.v3 v3.0.1
)
@ -21,8 +23,10 @@ require (
github.com/charmbracelet/lipgloss v0.13.0 // indirect
github.com/charmbracelet/x/ansi v0.4.0 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
@ -49,9 +53,11 @@ require (
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect

15
go.sum
View File

@ -20,10 +20,17 @@ github.com/charmbracelet/x/ansi v0.4.0 h1:NqwHA4B23VwsDn4H3VcNX1W1tOmgnvY1NDx5tO
github.com/charmbracelet/x/ansi v0.4.0/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -81,6 +88,8 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
@ -114,6 +123,7 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
@ -139,6 +149,10 @@ github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVK
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
@ -167,6 +181,7 @@ golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -27,6 +27,10 @@ func InitCmd() (*cobra.Command, error) {
flags.StringP("conf", "c", "config.yml", "指定配置文件")
_ = rootCmd.ParseFlags(os.Args)
//rootCmd.GenBashCompletion(os.Stdout)
//rootCmd.GenPowerShellCompletion(os.Stdout)
//rootCmd.GenZshCompletion(os.Stdout)
conf.InitAppConfig()
err := rootCmd.Execute()

View File

@ -2,10 +2,14 @@ package cmd
import (
"acme-mana/src/common"
"acme-mana/src/conf"
"acme-mana/src/http"
"acme-mana/src/util"
"encoding/json"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
"strconv"
)
// 打印 配置信息
@ -19,14 +23,18 @@ func confShow(cmd *cobra.Command, args []string) {
}
func editServer(cmd *cobra.Command, args []string) {
fmt.Println("edit server")
server := common.AppConf.Server
server.Host = util.ReadLine("请输入服务监听地址;", server.Host)
server.Port = util.ReadInt("请输入服务监听端口;", strconv.Itoa(server.Port))
conf.WriteConfig()
fmt.Println("服务监听配置已完成")
}
func serverState(cmd *cobra.Command, args []string) {
fmt.Println("server state")
http.Start()
}
func startServer(cmd *cobra.Command, args []string) {
fmt.Println("start server")
http.Start()
}
func stopServer(cmd *cobra.Command, args []string) {
fmt.Println("stop server")

27
src/cmd/tea/readline.go Normal file
View File

@ -0,0 +1,27 @@
package tea_programe
import tea "github.com/charmbracelet/bubbletea"
type Readline struct {
Line string
}
func (m Readline) Init() tea.Cmd {
return nil
}
func (m Readline) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
if msg.String() == "enter" {
return m, tea.Quit
}
m.Line += msg.String()
return m, nil
}
return m, nil
}
func (m Readline) View() string {
return m.Line
}

View File

@ -41,6 +41,14 @@ func RefreshConfig() {
readAppConfig(common.AppConf)
}
func WriteConfig() {
confFile, err := common.RootCmd.PersistentFlags().GetString("conf")
if err != nil {
log.Fatalln("读取配置文件参数失败")
}
writeConf(common.AppConf, confFile)
}
func writeConf(c *model.AppConfig, file string) {
out, err := yaml.Marshal(c)
if err != nil {

18
src/http/handler.go Normal file
View File

@ -0,0 +1,18 @@
package http
import (
"fmt"
"github.com/gin-gonic/gin"
)
func domainList(context *gin.Context) {
fmt.Println("domainList")
}
func getCert(context *gin.Context) {
fmt.Println("getCert")
}
func refreshCert(context *gin.Context) {
fmt.Println("refreshCert")
}

42
src/http/server.go Normal file
View File

@ -0,0 +1,42 @@
package http
import (
"acme-mana/src/common"
"github.com/gin-gonic/gin"
"github.com/go-acme/lego/v4/log"
"strconv"
)
var service *gin.Engine
var isRunning bool
func Start() {
}
func Stop() {
}
func Status() bool {
return isRunning
}
func start() {
conf := common.AppConf
server := conf.Server
service := gin.Default()
register(service)
isRunning = true
err := service.Run(server.Host + ":" + strconv.Itoa(server.Port))
if err != nil {
log.Fatal("http server start error \n", err)
}
isRunning = false
}
func register(service *gin.Engine) {
service.GET("/api/v1/refresh", refreshCert)
service.GET("/api/v1/cert", getCert)
service.GET("/api/v1/domain/list", domainList)
}

33
src/util/bash.go Normal file
View File

@ -0,0 +1,33 @@
package util
import (
"fmt"
"github.com/manifoldco/promptui"
"strconv"
)
func ReadLine(label string, defaultContent string) string {
for {
prompt := &promptui.Prompt{
Label: label,
Default: defaultContent,
}
line, err := prompt.Run()
if err != nil {
fmt.Println("输入错误:", err)
continue
}
return line
}
}
func ReadInt(label string, defaultContent string) int {
for {
line := ReadLine(label, defaultContent)
intValue, err := strconv.Atoi(line)
if err != nil {
fmt.Println("输入错误, 请输入整数:", err)
continue
}
return intValue
}
}