提交 48054864 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

update build script for windows

上级 9a897af0
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
$>zd.exe -y demo/test.yaml -c 15 -field field1 -o demo/output.txt -f text $>zd.exe -y demo/test.yaml -c 15 -field field1 -o demo/output.txt -f text
执行数据生成命令。使用配置文件demo/test.yaml,生成15行数据,以text格式的输出到demo/output.txt文件中。 执行数据生成命令。使用配置文件demo/test.yaml,生成15行数据,以text格式的输出到demo/output.txt文件中。
$>zd.exe -y demo/test.yaml -c 15 -s
执行数据生成命令。使用配置文件demo/test.yaml,生成15行数据,以行列的json形式输出到http://<ip_address/data接口。
$>zd.exe -y demo/test.yaml -c 15 -field field1 -o demo/insert.sql -f sql -t table_name $>zd.exe -y demo/test.yaml -c 15 -field field1 -o demo/insert.sql -f sql -t table_name
执行数据生成命令。以SQL语句形式输出到demo/insert.sql文件中,表名为table_name。 执行数据生成命令。以SQL语句形式输出到demo/insert.sql文件中,表名为table_name。
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
-c --count 指定生成数据的条数 -c --count 指定生成数据的条数
--field 需要输出的字段,用逗号分隔。未指定时,默认输出-yaml文件中的所有字段。 --field 需要输出的字段,用逗号分隔。未指定时,默认输出-yaml文件中的所有字段。
-o --out 指定输出文件 -o --out 指定输出文件
-f --format 输出格式,支持text、json、xml和sql语句,默认为text。 -f --format 输出格式,支持text、json、xml和sql语句,默认为text。
-t --table 输出格式为table时,用于指定insert语句的表名 -t --table 输出格式为table时,用于指定insert语句的表名
-s --service 启动http服务,用户可从http://<ip_address/data接口获取json格式的行列数据。
--verbose 增加此参数,显示详细调试信息。 --verbose 增加此参数,显示详细调试信息。
为了方便在任意目录中执行%s命令,建议将其加入环境变量中,具体方法参照以下地址。 为了方便在任意目录中执行%s命令,建议将其加入环境变量中,具体方法参照以下地址。
......
...@@ -84,6 +84,10 @@ ...@@ -84,6 +84,10 @@
{ {
"id": "generate_yaml", "id": "generate_yaml",
"translation": "Generate %d yaml files in %s, spend %d secs." "translation": "Generate %d yaml files in %s, spend %d secs."
},
{
"id": "press_to_exist",
"translation": "Press ctrl+c to exist."
} }
] ]
} }
\ No newline at end of file
...@@ -75,6 +75,10 @@ ...@@ -75,6 +75,10 @@
{ {
"id": "generate_yaml", "id": "generate_yaml",
"translation": "生成%d个yaml文件于目录%s中, 耗时%d秒。" "translation": "生成%d个yaml文件于目录%s中, 耗时%d秒。"
},
{
"id": "press_to_exist",
"translation": "按ctrl+c键推出。"
} }
] ]
} }
\ No newline at end of file
...@@ -7,8 +7,11 @@ import ( ...@@ -7,8 +7,11 @@ import (
"github.com/easysoft/zendata/src/gen" "github.com/easysoft/zendata/src/gen"
"github.com/easysoft/zendata/src/model" "github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const" constant "github.com/easysoft/zendata/src/utils/const"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log" logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari" "github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -31,17 +34,30 @@ func Generate(deflt string, yml string, total int, fieldsToExportStr string, out ...@@ -31,17 +34,30 @@ func Generate(deflt string, yml string, total int, fieldsToExportStr string, out
constant.Total = total constant.Total = total
rows, colTypes := gen.GenerateForDefinition(deflt, yml, &fieldsToExport, total) rows, colTypes := gen.GenerateForDefinition(deflt, yml, &fieldsToExport, total)
content := Print(rows, format, table, colTypes, fieldsToExport) var content string
content, vari.JsonResp = Print(rows, format, table, colTypes, fieldsToExport)
if out != "" { if out != "" {
WriteToFile(out, content) WriteToFile(out, content)
} }
if out != "" {
WriteToFile(out, content)
}
if vari.HttpService {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("press_to_exist"), color.FgCyan)
http.HandleFunc("/", DataHandler)
http.HandleFunc("/data", DataHandler)
http.ListenAndServe(":58848", nil)
}
//entTime := time.Now().Unix() //entTime := time.Now().Unix()
//logUtils.Screen(i118Utils.I118Prt.Sprintf("generate_records", len(rows), out, entTime - startTime )) //logUtils.Screen(i118Utils.I118Prt.Sprintf("generate_records", len(rows), out, entTime - startTime ))
} }
func Print(rows [][]string, format string, table string, colTypes []bool, fields []string) string { func Print(rows [][]string, format string, table string, colTypes []bool, fields []string) (string, string) {
content := "" content := ""
sql := "" sql := ""
...@@ -86,15 +102,25 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields ...@@ -86,15 +102,25 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
} }
} }
if format == "json" { jsonStr := "[]"
json, _ := json.Marshal(rows) if format == "json" || vari.HttpService {
content = string(json) jsonObj, _ := json.Marshal(rows)
} else if format == "xml" { content = string(jsonObj)
if vari.HttpService {
jsonStr = content
}
}
if format == "xml" {
xml, _ := xml.Marshal(testData) xml, _ := xml.Marshal(testData)
content = string(xml) content = string(xml)
} else if format == "sql" { } else if format == "sql" {
content = sql content = sql
} }
return content return content, jsonStr
}
func DataHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, vari.JsonResp)
} }
\ No newline at end of file
...@@ -21,4 +21,7 @@ var ( ...@@ -21,4 +21,7 @@ var (
RequestType string RequestType string
Verbose bool Verbose bool
Interpreter string Interpreter string
HttpService bool
JsonResp string = "[]"
) )
...@@ -69,6 +69,8 @@ func main() { ...@@ -69,6 +69,8 @@ func main() {
flagSet.StringVar(&viewRes, "v", "", "") flagSet.StringVar(&viewRes, "v", "", "")
flagSet.StringVar(&viewDetail, "vv", "", "") flagSet.StringVar(&viewDetail, "vv", "", "")
flagSet.BoolVar(&vari.HttpService, "s", false, "")
flagSet.BoolVar(&vari.Verbose, "verbose", false, "") flagSet.BoolVar(&vari.Verbose, "verbose", false, "")
if len(os.Args) == 1 { if len(os.Args) == 1 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册