From 18ca37514b24f3d3ab1b21909c0dee81eb69f3a9 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Thu, 29 Dec 2022 14:21:07 +0800 Subject: [PATCH] fix package issue issues --- .zd.conf | 2 +- Makefile | 2 +- cmd/command/main.go | 50 +++++++++++++++++++++++++++++-- cmd/server/main.go | 47 ----------------------------- internal/pkg/const/const.go | 7 ++--- internal/server/config/config.go | 2 -- internal/server/core/web/index.go | 3 +- pkg/utils/vari/var.go | 1 - res/en/usage.txt | 2 +- res/zh/usage.txt | 2 +- ui/src/utils/request.js | 4 ++- 11 files changed, 59 insertions(+), 63 deletions(-) diff --git a/.zd.conf b/.zd.conf index 4a97cdbe..ae6d9211 100644 --- a/.zd.conf +++ b/.zd.conf @@ -1,3 +1,3 @@ -Version = 2.2 +Version = 2.3 Language = zh diff --git a/Makefile b/Makefile index 6dbf72b3..53d12ea6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=3.0 +VERSION=2.3 PROJECT=zd QINIU_DIR=/Users/aaron/work/zentao/qiniu/ QINIU_DIST_DIR=${QINIU_DIR}${PROJECT}/${VERSION}/ diff --git a/cmd/command/main.go b/cmd/command/main.go index 00fe24c6..0d102451 100644 --- a/cmd/command/main.go +++ b/cmd/command/main.go @@ -8,7 +8,11 @@ import ( consts "github.com/easysoft/zendata/internal/pkg/const" "github.com/easysoft/zendata/internal/pkg/gen" "github.com/easysoft/zendata/internal/pkg/helper" + serverConfig "github.com/easysoft/zendata/internal/server/config" + "github.com/easysoft/zendata/internal/server/core/web" + serverConst "github.com/easysoft/zendata/internal/server/utils/const" fileUtils "github.com/easysoft/zendata/pkg/utils/file" + i118Utils "github.com/easysoft/zendata/pkg/utils/i118" logUtils "github.com/easysoft/zendata/pkg/utils/log" "github.com/easysoft/zendata/pkg/utils/vari" "github.com/fatih/color" @@ -43,6 +47,9 @@ var ( help bool set bool + isStartServer bool + uuid = "" + flagSet *flag.FlagSet ) @@ -117,8 +124,8 @@ func main() { flagSet.StringVar(&vari.GlobalVars.Table, "t", "", "") flagSet.StringVar(&vari.GlobalVars.Table, "table", "", "") flagSet.StringVar(&vari.GlobalVars.DBDsn, "dsn", "", "") - flagSet.StringVar(&vari.GlobalVars.DBType, "s", "mysql", "") - flagSet.StringVar(&vari.GlobalVars.DBType, "server", "mysql", "") + flagSet.StringVar(&vari.GlobalVars.DBType, "db", "db", "") + flagSet.StringVar(&vari.GlobalVars.DBType, "server", "mysql", "") // TODO: will remove flagSet.BoolVar(&vari.GlobalVars.DBClear, "clear", false, "") flagSet.StringVar(&vari.ProtoCls, "cls", "", "") @@ -128,6 +135,22 @@ func main() { flagSet.BoolVar(&help, "h", false, "") flagSet.BoolVar(&help, "help", false, "") + // for server + flagSet.BoolVar(&isStartServer, "s", false, "启动服务") + flagSet.StringVar(&uuid, "uuid", "", "区分服务进程的唯一ID") + + flagSet.IntVar(&vari.DataServicePort, "p", 8848, "") + flagSet.IntVar(&vari.DataServicePort, "port", 0, "") + + flagSet.Parse(os.Args[1:]) + if isStartServer { + startServer() + } else { + execCommand() + } +} + +func execCommand() { if len(os.Args) == 1 { os.Args = append(os.Args, "-help") } @@ -150,6 +173,29 @@ func main() { } } +func startServer() { + configUtils.InitConfig("") + vari.DB, _ = serverConfig.NewGormDB() + + vari.AgentLogDir = vari.ZdPath + serverConst.AgentLogDir + consts.PthSep + err := fileUtils.MkDirIfNeeded(vari.AgentLogDir) + if err != nil { + logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("perm_deny", vari.AgentLogDir), color.FgRed) + os.Exit(1) + } + + if vari.DataServicePort == 0 { + vari.DataServicePort = consts.DefaultDataServicePort + } + + webServer := web.Init() + if webServer == nil { + return + } + + webServer.Run() +} + func opts(files []string) { if exportFields != "" { vari.GlobalVars.ExportFields = strings.Split(exportFields, ",") diff --git a/cmd/server/main.go b/cmd/server/main.go index 3d33c760..3991d88e 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -2,12 +2,8 @@ package main import ( "flag" - "fmt" - zd "github.com/easysoft/zendata" - "github.com/easysoft/zendata/internal/agent" configUtils "github.com/easysoft/zendata/internal/pkg/config" consts "github.com/easysoft/zendata/internal/pkg/const" - "github.com/easysoft/zendata/internal/server" serverConfig "github.com/easysoft/zendata/internal/server/config" "github.com/easysoft/zendata/internal/server/core/web" serverConst "github.com/easysoft/zendata/internal/server/utils/const" @@ -17,10 +13,8 @@ import ( logUtils "github.com/easysoft/zendata/pkg/utils/log" "github.com/easysoft/zendata/pkg/utils/vari" "github.com/fatih/color" - "net/http" "os" "os/signal" - "strconv" "syscall" ) @@ -65,33 +59,6 @@ func main() { vari.DataServicePort = consts.DefaultDataServicePort } - //go func() { - // startDataServer() - //}() - - startServer() -} - -func startDataServer() { - port := strconv.Itoa(vari.DataServicePort) - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server", - vari.Ip, port, vari.Ip, port, vari.Ip, port), color.FgCyan) - - config := serverConfig.NewConfig() - server, err := server.InitServer(config) - if err != nil { - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server_fail", port), color.FgRed) - } - - httpServer := &http.Server{ - Addr: fmt.Sprintf(":%d", server.Config.ServerPort), - Handler: dataHandler(server), - } - - httpServer.ListenAndServe() -} - -func startServer() { webServer := web.Init() if webServer == nil { return @@ -100,20 +67,6 @@ func startServer() { webServer.Run() } -func dataHandler(server *server.Server) http.Handler { - mux := http.NewServeMux() - - uiFs, err := zd.GetUiFileSys() - if err != nil { - panic(err) - } - mux.Handle("/", http.FileServer(http.FS(uiFs))) - - mux.HandleFunc("/data", agent.DataHandler) - - return mux -} - func init() { cleanup() } diff --git a/internal/pkg/const/const.go b/internal/pkg/const/const.go index f9ed91ea..169d5644 100644 --- a/internal/pkg/const/const.go +++ b/internal/pkg/const/const.go @@ -68,10 +68,9 @@ var ( RightBrackets rune = ')' Backtick rune = '`' - DefaultDataServicePort = 8848 - DefaultAdminServicePort = 8085 - DefaultRoot = "./" - DefaultNumber = 10 + DefaultDataServicePort = 8848 + DefaultRoot = "./" + DefaultNumber = 10 ResDirData = "data" ResDirYaml = "yaml" diff --git a/internal/server/config/config.go b/internal/server/config/config.go index 06032f3e..19aa6623 100644 --- a/internal/server/config/config.go +++ b/internal/server/config/config.go @@ -5,13 +5,11 @@ import ( ) type Config struct { - ServerIP string ServerPort int } func NewConfig() *Config { return &Config{ - ServerIP: vari.Ip, ServerPort: vari.DataServicePort, } } diff --git a/internal/server/core/web/index.go b/internal/server/core/web/index.go index 5cee16ad..ace260de 100644 --- a/internal/server/core/web/index.go +++ b/internal/server/core/web/index.go @@ -4,7 +4,6 @@ import ( stdContext "context" "fmt" zd "github.com/easysoft/zendata" - consts "github.com/easysoft/zendata/internal/pkg/const" "github.com/easysoft/zendata/internal/server" "github.com/easysoft/zendata/internal/server/core/module" logUtils "github.com/easysoft/zendata/pkg/utils/log" @@ -51,7 +50,7 @@ func Init() *WebServer { mvc.New(app) - addr := fmt.Sprintf(":%d", consts.DefaultAdminServicePort) + addr := fmt.Sprintf(":%d", vari.DataServicePort) webServer := &WebServer{ app: app, diff --git a/pkg/utils/vari/var.go b/pkg/utils/vari/var.go index bbf47170..2bb75dab 100644 --- a/pkg/utils/vari/var.go +++ b/pkg/utils/vari/var.go @@ -78,7 +78,6 @@ var ( ProtoCls string JsonResp string = "[]" - Ip string DataServicePort int ResLoading = false diff --git a/res/en/usage.txt b/res/en/usage.txt index 32efbe0a..3a1aa14b 100644 --- a/res/en/usage.txt +++ b/res/en/usage.txt @@ -6,7 +6,7 @@ Parameters: -c --config The current config file for data format, and it can override the config in the default file. -o --output The file name of the data generated. You can specify the output format by the extension name. For example json, xml, sql, csv and xlsx. The text data in the original format is output by default. - Note: For SQL files, you can use --server to specify a specific database type in Mysql\Oracle\SqlServer. + Note: For SQL files, you can use --db to specify a specific database type in Mysql,Oracle,SqlServer. -n --lines The number of lines of data to be generated. The default is 10. -F --field This parameter can be used to specify the fields, separated by commas. The default is all fields. diff --git a/res/zh/usage.txt b/res/zh/usage.txt index 6798bab0..be14b6e5 100644 --- a/res/zh/usage.txt +++ b/res/zh/usage.txt @@ -5,7 +5,7 @@ ZenData是一款通用的数据生成工具,您可以使用yaml文件来定义 -d --default 默认的数据格式配置文件。 -c --config 当前场景的数据格式配置文件,可以覆盖默认文件里面的设置。 -o --output 生成的数据的文件名。可通过扩展名指定输出json|xml|sql|csv|xlsx格式的数据。默认输出原始格式的文本数据。 - 注意:对于 SQL 文件,您可以使用 --server 指定Mysql\Oracle\SqlServer中具体的数据库类型。 + 注意:对于 SQL 文件,您可以使用 --db 指定Mysql、Oracle、SqlServer中具体的数据库类型。 -n --lines 要生成的记录条数,默认为10条。 -F --field 可通过该参数指定要输出的字段列表,用逗号分隔。 默认是所有的字段。 diff --git a/ui/src/utils/request.js b/ui/src/utils/request.js index 51db461a..765fc5c4 100644 --- a/ui/src/utils/request.js +++ b/ui/src/utils/request.js @@ -17,12 +17,14 @@ function initRequest(remoteUrl) { function getUrl() { let url = '' if (process.env.NODE_ENV === "development") { - url = 'http://127.0.0.1:8085/api/v1' + url = 'http://127.0.0.1:8848/api/v1' console.log('dev env, url is ' + url) + } else { const location = unescape(window.location.href); url = location.split('#')[0].split('index.html')[0]; console.log('prod env, url is ' + url) + } return url -- GitLab