diff --git a/.zd.conf b/.zd.conf index 4a97cdbe90a54bc5acf2d40b62717eb01897b4be..ae6d92110a1300c61b6697629ad1ae2b0eb81c33 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 6dbf72b3fff0ccab324cd29ed29bbb625094174a..53d12ea6bd6a1f256c5e1fba657b188dcbbf6487 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 00fe24c60120e97046c1ae3c9e49048ebce64274..0d102451fb0e0b889ec1fa07f2ad95c50789918b 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 3d33c76067116adea80765a03bfbbb4ac9a955e1..3991d88e633771263e9111e6c90d9bf9663bb76d 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 f9ed91ea3558a6acb6e6768f240562b1bbb61ba6..169d5644eb05a9c7908ac92b670bb4d21b249b34 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 06032f3e8b7018d955b8dc5fe2e57e216d5a7a73..19aa66238619d56ae091fb65f76397c974eb55f7 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 5cee16ad2bb893cb68c2f88971d52d5ea6524b54..ace260de0dbbe36d74173139d13ed8e8004b6510 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 bbf47170db57441bc262e73b404e027f05a0d7bb..2bb75dabee26df04d0a088e15b87f6737273acee 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 32efbe0aa455655abd42563e0489fed3973f6b74..3a1aa14ba16fc5a3ea4f4674b5ff1af7ce274085 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 6798bab0d27a04a55c9dff06655e6a8fb52409ec..be14b6e50e65ace292108ed0a41e469f4249eb9f 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 51db461a04fab60b9c20ee0583a6113ebbf0bda3..765fc5c47a4f99580048e6078b2727412ceaeb94 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