embed
This commit is contained in:
		
							parent
							
								
									4b43bc3533
								
							
						
					
					
						commit
						ad99da70fb
					
				| 
						 | 
					@ -96,6 +96,14 @@ func initServerCmd() *cobra.Command {
 | 
				
			||||||
			cmd_handle.ServerStart(cmd, args)
 | 
								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{
 | 
						stopCmd := &cobra.Command{
 | 
				
			||||||
		Use:   "stop",
 | 
							Use:   "stop",
 | 
				
			||||||
		Short: "停止服务",
 | 
							Short: "停止服务",
 | 
				
			||||||
| 
						 | 
					@ -108,6 +116,7 @@ func initServerCmd() *cobra.Command {
 | 
				
			||||||
	serverCmd.AddCommand(editCmd)
 | 
						serverCmd.AddCommand(editCmd)
 | 
				
			||||||
	serverCmd.AddCommand(stateCmd)
 | 
						serverCmd.AddCommand(stateCmd)
 | 
				
			||||||
	serverCmd.AddCommand(startCmd)
 | 
						serverCmd.AddCommand(startCmd)
 | 
				
			||||||
 | 
						serverCmd.AddCommand(runCmd)
 | 
				
			||||||
	serverCmd.AddCommand(stopCmd)
 | 
						serverCmd.AddCommand(stopCmd)
 | 
				
			||||||
	return serverCmd
 | 
						return serverCmd
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ import (
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"syscall"
 | 
						"syscall"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,12 +63,18 @@ func ServerStart(command *cobra.Command, args []string) {
 | 
				
			||||||
	os.Exit(0)
 | 
						os.Exit(0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func RunStart(command *cobra.Command, args []string) {
 | 
				
			||||||
 | 
						daemonStart()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ServerEdit(cmd *cobra.Command, args []string) {
 | 
					func ServerEdit(cmd *cobra.Command, args []string) {
 | 
				
			||||||
	s := conf.Config().Server
 | 
						s := conf.Config().Server
 | 
				
			||||||
	host := util.ReadLine("请输入服务监听地址;", s.Host)
 | 
						host := util.ReadLine("请输入服务监听地址;", s.Host)
 | 
				
			||||||
	port := util.ReadInt("请输入服务监听端口;", strconv.Itoa(s.Port))
 | 
						port := util.ReadInt("请输入服务监听端口;", strconv.Itoa(s.Port))
 | 
				
			||||||
	key := util.ReadLine("请输入服务通信认证秘钥;", s.Key)
 | 
						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("服务监听配置已完成")
 | 
						fmt.Println("服务监听配置已完成")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,10 +6,11 @@ func Config() *AppConfig {
 | 
				
			||||||
	return appConf
 | 
						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.Host = host
 | 
				
			||||||
	appConf.Server.Port = port
 | 
						appConf.Server.Port = port
 | 
				
			||||||
	appConf.Server.Key = key
 | 
						appConf.Server.Key = key
 | 
				
			||||||
 | 
						appConf.Server.Web = web
 | 
				
			||||||
	WriteConfig()
 | 
						WriteConfig()
 | 
				
			||||||
	return appConf
 | 
						return appConf
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import (
 | 
				
			||||||
	"acme-mana/src/conf"
 | 
						"acme-mana/src/conf"
 | 
				
			||||||
	"acme-mana/src/server/http_handler"
 | 
						"acme-mana/src/server/http_handler"
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
						"embed"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
| 
						 | 
					@ -12,6 +13,9 @@ import (
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//go:embed static/*
 | 
				
			||||||
 | 
					var staticFiles embed.FS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type HttpServer struct {
 | 
					type HttpServer struct {
 | 
				
			||||||
	server *http.Server
 | 
						server *http.Server
 | 
				
			||||||
	status bool
 | 
						status bool
 | 
				
			||||||
| 
						 | 
					@ -69,6 +73,9 @@ func (s *HttpServer) register() {
 | 
				
			||||||
	service.Use(gin.Logger())
 | 
						service.Use(gin.Logger())
 | 
				
			||||||
	service.Use(http_handler.GlobalErrorHandler())
 | 
						service.Use(http_handler.GlobalErrorHandler())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs := http.FileServer(http.FS(staticFiles))
 | 
				
			||||||
 | 
						http.Handle("/static/", http.StripPrefix("/static/", fs))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	certHandler := http_handler.CertHandlerInstance
 | 
						certHandler := http_handler.CertHandlerInstance
 | 
				
			||||||
	certGroup := service.Group("/api/v1/cert", http_handler.AuthMiddleware())
 | 
						certGroup := service.Group("/api/v1/cert", http_handler.AuthMiddleware())
 | 
				
			||||||
	certGroup.GET("/", certHandler.Get)
 | 
						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 (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/manifoldco/promptui"
 | 
						"github.com/manifoldco/promptui"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +14,9 @@ func ReadLine(label string, defaultContent string) string {
 | 
				
			||||||
			Default: defaultContent,
 | 
								Default: defaultContent,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		line, err := prompt.Run()
 | 
							line, err := prompt.Run()
 | 
				
			||||||
 | 
							if err.Error() == "^D" || err.Error() == "^C" {
 | 
				
			||||||
 | 
								os.Exit(0)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			fmt.Println("输入错误:", err)
 | 
								fmt.Println("输入错误:", err)
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user