embed
This commit is contained in:
parent
4b43bc3533
commit
ad99da70fb
|
@ -96,6 +96,14 @@ func initServerCmd() *cobra.Command {
|
|||
cmd_handle.ServerStart(cmd, args)
|
||||
},
|
||||
}
|
||||
runCmd := &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "前台运行服务",
|
||||
Long: "前台运行服务",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd_handle.RunStart(cmd, args)
|
||||
},
|
||||
}
|
||||
stopCmd := &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "停止服务",
|
||||
|
@ -108,6 +116,7 @@ func initServerCmd() *cobra.Command {
|
|||
serverCmd.AddCommand(editCmd)
|
||||
serverCmd.AddCommand(stateCmd)
|
||||
serverCmd.AddCommand(startCmd)
|
||||
serverCmd.AddCommand(runCmd)
|
||||
serverCmd.AddCommand(stopCmd)
|
||||
return serverCmd
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
@ -62,12 +63,18 @@ func ServerStart(command *cobra.Command, args []string) {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
func RunStart(command *cobra.Command, args []string) {
|
||||
daemonStart()
|
||||
}
|
||||
|
||||
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)
|
||||
web := util.ReadLine("是否启用WEB服务; Y(es)/N(o);", s.Key)
|
||||
openWeb := strings.ToUpper(web) == "Y" || strings.ToUpper(web) == "YES"
|
||||
conf.EditServer(host, port, key, openWeb)
|
||||
fmt.Println("服务监听配置已完成")
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,11 @@ func Config() *AppConfig {
|
|||
return appConf
|
||||
}
|
||||
|
||||
func EditServer(host string, port int, key string) *AppConfig {
|
||||
func EditServer(host string, port int, key string, web bool) *AppConfig {
|
||||
appConf.Server.Host = host
|
||||
appConf.Server.Port = port
|
||||
appConf.Server.Key = key
|
||||
appConf.Server.Web = web
|
||||
WriteConfig()
|
||||
return appConf
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"acme-mana/src/conf"
|
||||
"acme-mana/src/server/http_handler"
|
||||
"context"
|
||||
"embed"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
|
@ -12,6 +13,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
//go:embed static/*
|
||||
var staticFiles embed.FS
|
||||
|
||||
type HttpServer struct {
|
||||
server *http.Server
|
||||
status bool
|
||||
|
@ -69,6 +73,9 @@ func (s *HttpServer) register() {
|
|||
service.Use(gin.Logger())
|
||||
service.Use(http_handler.GlobalErrorHandler())
|
||||
|
||||
fs := http.FileServer(http.FS(staticFiles))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||
|
||||
certHandler := http_handler.CertHandlerInstance
|
||||
certGroup := service.Group("/api/v1/cert", http_handler.AuthMiddleware())
|
||||
certGroup.GET("/", certHandler.Get)
|
||||
|
|
10
src/server/static/index.html
Normal file
10
src/server/static/index.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
123123
|
||||
</body>
|
||||
</html>
|
|
@ -3,6 +3,7 @@ package util
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/manifoldco/promptui"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
@ -13,6 +14,9 @@ func ReadLine(label string, defaultContent string) string {
|
|||
Default: defaultContent,
|
||||
}
|
||||
line, err := prompt.Run()
|
||||
if err.Error() == "^D" || err.Error() == "^C" {
|
||||
os.Exit(0)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("输入错误:", err)
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue
Block a user