Compare commits

..

No commits in common. "55d241b873b2e478fc4322e74aef51fe45c4cb67" and "6ed343cf06b509d59eb266e632b2ef9910229aa3" have entirely different histories.

20 changed files with 19 additions and 406 deletions

View File

@ -1,12 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="block" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="acme-mana" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="block" />
<kind value="PACKAGE" />
<package value="acme-mana" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
</component>

View File

@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-darwin-amd64" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="build">
<module name="acme-mana" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-o bin/acme-mana-darwin-amd64" />
<envs>
<env name="GOARCH" value="amd64" />
<env name="GOOS" value="darwin" />
</envs>
<kind value="PACKAGE" />
<package value="acme-mana" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<option name="run" value="false" />
<method v="2" />
</configuration>
</component>

View File

@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-linux-amd64" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="build">
<module name="acme-mana" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-o bin/acme-mana-linux-amd64" />
<envs>
<env name="GOARCH" value="amd64" />
<env name="GOOS" value="linux" />
</envs>
<kind value="PACKAGE" />
<package value="acme-mana" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<option name="run" value="false" />
<method v="2" />
</configuration>
</component>

View File

@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-windows-amd64" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="build">
<module name="acme-mana" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-o bin/acme-mana-windows-amd64.exe" />
<envs>
<env name="GOARCH" value="amd64" />
<env name="GOOS" value="windows" />
</envs>
<kind value="PACKAGE" />
<package value="acme-mana" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<option name="run" value="false" />
<method v="2" />
</configuration>
</component>

View File

@ -1,12 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="conf show" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="acme-mana" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="conf show" />
<kind value="PACKAGE" />
<package value="acme-mana" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
</component>

View File

@ -1,12 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="help" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="acme-mana" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="help" />
<kind value="PACKAGE" />
<package value="acme-mana" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
</component>

6
go.mod
View File

@ -8,9 +8,7 @@ require (
github.com/charmbracelet/bubbletea v1.1.2 github.com/charmbracelet/bubbletea v1.1.2
github.com/gin-gonic/gin v1.10.0 github.com/gin-gonic/gin v1.10.0
github.com/go-acme/lego/v4 v4.19.1 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/spf13/cobra v1.8.1
github.com/urfave/cli/v2 v2.27.4
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
@ -23,10 +21,8 @@ require (
github.com/charmbracelet/lipgloss v0.13.0 // indirect github.com/charmbracelet/lipgloss v0.13.0 // indirect
github.com/charmbracelet/x/ansi v0.4.0 // indirect github.com/charmbracelet/x/ansi v0.4.0 // indirect
github.com/charmbracelet/x/term v0.2.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/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // 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/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
@ -53,11 +49,9 @@ require (
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // 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/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // 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/arch v0.8.0 // indirect
golang.org/x/crypto v0.27.0 // indirect golang.org/x/crypto v0.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect golang.org/x/mod v0.21.0 // indirect

15
go.sum
View File

@ -20,17 +20,10 @@ 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/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 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= 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 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= 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 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= 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/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/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= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -88,8 +81,6 @@ 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/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 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 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 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 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= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
@ -123,7 +114,6 @@ 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.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 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/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 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
@ -149,10 +139,6 @@ 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/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 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= 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 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
@ -181,7 +167,6 @@ 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.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 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 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-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-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -1,10 +1,7 @@
package cmd package cmd
import ( import (
"acme-mana/src/common"
"acme-mana/src/conf"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os"
) )
func InitCmd() (*cobra.Command, error) { func InitCmd() (*cobra.Command, error) {
@ -13,7 +10,6 @@ func InitCmd() (*cobra.Command, error) {
Short: "ACME协议客户端", Short: "ACME协议客户端",
Long: "基于 ACME 协议实现自动申请证书和续签证书", Long: "基于 ACME 协议实现自动申请证书和续签证书",
} }
common.RootCmd = rootCmd
rootCmd.AddCommand(initConfCmd()) rootCmd.AddCommand(initConfCmd())
rootCmd.AddCommand(initServerCmd()) rootCmd.AddCommand(initServerCmd())
@ -22,18 +18,7 @@ func InitCmd() (*cobra.Command, error) {
rootCmd.AddCommand(certCmd()) rootCmd.AddCommand(certCmd())
rootCmd.AddCommand(acmeCmd()) rootCmd.AddCommand(acmeCmd())
flags := rootCmd.PersistentFlags()
flags.BoolP("force", "f", false, "强制执行")
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() err := rootCmd.Execute()
return rootCmd, err return rootCmd, err
} }

View File

@ -1,40 +1,23 @@
package cmd package cmd
import ( import (
"acme-mana/src/common"
"acme-mana/src/conf"
"acme-mana/src/http"
"acme-mana/src/util"
"encoding/json"
"fmt" "fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"strconv"
) )
// 打印 配置信息
func confShow(cmd *cobra.Command, args []string) { func confShow(cmd *cobra.Command, args []string) {
tea.Println() fmt.Println("show conf")
confJson, err := json.MarshalIndent(common.AppConf, "", " ")
if err != nil {
fmt.Println("序列化配置信息失败:", err)
}
fmt.Println(string(confJson))
} }
func editServer(cmd *cobra.Command, args []string) { func editServer(cmd *cobra.Command, args []string) {
server := common.AppConf.Server fmt.Println("edit 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) { func serverState(cmd *cobra.Command, args []string) {
http.Start() fmt.Println("server state")
} }
func startServer(cmd *cobra.Command, args []string) { func startServer(cmd *cobra.Command, args []string) {
http.Start() fmt.Println("start server")
} }
func stopServer(cmd *cobra.Command, args []string) { func stopServer(cmd *cobra.Command, args []string) {
fmt.Println("stop server") fmt.Println("stop server")

View File

@ -1,27 +0,0 @@
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

@ -1,10 +0,0 @@
package common
import (
"acme-mana/src/model"
"github.com/spf13/cobra"
)
var RootCmd *cobra.Command
var AppConf *model.AppConfig

View File

@ -1,77 +0,0 @@
package conf
import (
"acme-mana/src/common"
"acme-mana/src/model"
"acme-mana/src/util"
"gopkg.in/yaml.v3"
"log"
"os"
)
func readAppConfig(c *model.AppConfig) *model.AppConfig {
confFile, err := common.RootCmd.PersistentFlags().GetString("conf")
if err != nil {
log.Fatalln("读取配置文件参数失败")
}
_, err = os.Stat(confFile)
if os.IsNotExist(err) {
log.Println("配置文件不存在, 自动创建")
writeConf(c, confFile)
}
file, err := os.ReadFile(confFile)
if err != nil {
log.Fatalln("读取配置文件失败")
}
//var conf = &model.AppConfig{}
err = yaml.Unmarshal(file, c)
if err != nil {
log.Fatalln("解析配置文件失败")
}
return c
}
func InitAppConfig() {
common.AppConf = DefaultAppConfig()
}
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 {
log.Fatalln("序列化配置文件失败")
}
util.MkFileDir(file)
err = os.WriteFile(file, out, 0644)
if err != nil {
log.Fatalln("写入配置文件失败")
}
}
func DefaultAppConfig() *model.AppConfig {
return &model.AppConfig{
Server: &model.ServerConf{
Host: "0.0.0.0",
Port: 36851,
},
Task: &model.TaskConf{
Delay: 0,
Interval: 0,
},
Certs: nil,
Providers: nil,
}
}

View File

@ -12,9 +12,6 @@ import (
) )
func ReadConfig() *AppConfig { func ReadConfig() *AppConfig {
if DnsProviderSupports != nil {
return nil
}
InitConfig() InitConfig()
file, err := os.ReadFile(GetEnvConf().ConfFile) file, err := os.ReadFile(GetEnvConf().ConfFile)
if err != nil { if err != nil {

View File

@ -2,6 +2,7 @@ package src
import ( import (
"encoding/json" "encoding/json"
tea "github.com/charmbracelet/bubbletea"
"log" "log"
"net" "net"
"os" "os"
@ -75,6 +76,20 @@ func initLog() {
} }
func showHelp() { func showHelp() {
tea.Println("")
log.Printf(`
Usage: acme-mana [command] [options]
Commands:
help Show this help message
start Start the daemon
stop Stop the daemon
status Check the status of the daemon
dump Dump the configuration file
domains List all domains
pubkey Show the public key
apply Manually apply for a certificate
block Block the
`)
} }
// 守护进程启动 // 守护进程启动

View File

@ -1,18 +0,0 @@
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")
}

View File

@ -1,42 +0,0 @@
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)
}

View File

@ -1,34 +0,0 @@
package model
type AppConfig struct {
Server *ServerConf `json:"server" yaml:"server"`
Task *TaskConf `json:"task" yaml:"task"`
Certs *[]CertConf `json:"cert" yaml:"cert"`
Providers *[]ProviderConf `json:"provider" yaml:"provider"`
}
type ServerConf struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
}
type TaskConf struct {
// 启动延迟时间, 单位: 毫秒, 默认: 0
Delay int `json:"delay" yaml:"delay"`
// 间隔时间
Interval int `json:"interval" yaml:"interval"`
}
type ProviderConf struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
Conf map[string]string `json:"conf" yaml:"conf"`
}
type CertConf struct {
Name string `json:"name" yaml:"name"`
Provider string `json:"use" yaml:"provider"`
Dir string `json:"dir" yaml:"dir"`
Email string `json:"email" yaml:"email"`
Host []string `json:"host" yaml:"host"`
}

View File

@ -1,33 +0,0 @@
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
}
}

View File

@ -1,18 +0,0 @@
package util
import (
"log"
"os"
"path/filepath"
)
// MkFileDir 创建文件所在的目录
func MkFileDir(file string) {
dir := filepath.Dir(file)
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0755)
if err != nil {
log.Fatal("创建目录失败!", err)
}
}
}