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

test post request

上级 5524be68
...@@ -41,7 +41,7 @@ $>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 # Using the parameter of ...@@ -41,7 +41,7 @@ $>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 # Using the parameter of
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.txt # Output data in original format. $>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.txt # Output data in original format.
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.json # Output data in JSON. $>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.json # Output data in JSON.
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.xml # Output data in XML. $>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.xml # Output data in XML.
$>zd.exe -d demo/default.yaml -n 100 -o test.sql -t user -s mysql # Output the sql inserted into the table user. $>zd.exe -d demo/default.yaml -n 100 -o test.sql -t user # Output the sql inserted into the table user.
$>zd.exe -d demo/default.yaml -o test.sql -t user -s mysql --trim # Remove the prefix and postfix of every field. $>zd.exe -d demo/default.yaml -o test.sql -t user -s mysql --trim # Remove the prefix and postfix of every field.
$>zd.exe -i db.sql -o db # Generate YAML files for each table by parsing db.sql and store them in the db directory. $>zd.exe -i db.sql -o db # Generate YAML files for each table by parsing db.sql and store them in the db directory.
......
...@@ -35,7 +35,7 @@ $>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -c和-d两个文件的 ...@@ -35,7 +35,7 @@ $>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -c和-d两个文件的
$>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.txt 输出原始格式的数据。 $>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.txt 输出原始格式的数据。
$>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.json 输出json格式的数据。 $>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.json 输出json格式的数据。
$>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.xml 输出xml格式的数据。 $>zd.exe -d demo\default.yaml -c demo\test.yaml -n 100 -o test.xml 输出xml格式的数据。
$>zd.exe -d demo\default.yaml -n 100 -o test.sql -t user -s mysql 输出插入到user表里面的sql。 $>zd.exe -d demo\default.yaml -n 100 -o test.sql -t user 输出插入到user表里面的sql。
$>zd.exe -i db.sql -o db 根据db.sql的定义生成每个表的yaml文件,存储到db目录里面。 $>zd.exe -i db.sql -o db 根据db.sql的定义生成每个表的yaml文件,存储到db目录里面。
$>zd.exe -c demo\default.yaml -i test.txt --decode 将-i指定的文件根据-d参数的配置进行解析。 $>zd.exe -c demo\default.yaml -i test.txt --decode 将-i指定的文件根据-d参数的配置进行解析。
......
...@@ -3,6 +3,7 @@ package gen ...@@ -3,6 +3,7 @@ package gen
import ( import (
"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"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118" 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"
...@@ -17,32 +18,40 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod ...@@ -17,32 +18,40 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
configDef := model.DefData{} configDef := model.DefData{}
// load defaultDef // load defaultDef
path := vari.ExeDir + defaultFile
if defaultFile != "" { if defaultFile != "" {
defaultContent, err := ioutil.ReadFile(path) pathDefaultFile := defaultFile
if !fileUtils.IsAbosutePath(pathDefaultFile) {
pathDefaultFile = vari.ExeDir + pathDefaultFile
}
defaultContent, err := ioutil.ReadFile(pathDefaultFile)
defaultContent = ReplaceSpecialChars(defaultContent) defaultContent = ReplaceSpecialChars(defaultContent)
if err != nil { if err != nil {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_read_file", path), color.FgCyan) logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_read_file", pathDefaultFile), color.FgCyan)
return defaultDef return defaultDef
} }
err = yaml.Unmarshal(defaultContent, &defaultDef) err = yaml.Unmarshal(defaultContent, &defaultDef)
if err != nil { if err != nil {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_read_file", path), color.FgCyan) logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_read_file", pathDefaultFile), color.FgCyan)
return defaultDef return defaultDef
} }
} }
// load configDef // load configDef
path = vari.ExeDir + configFile pathConfigFile := configFile
yamlContent, err := ioutil.ReadFile(path) if !fileUtils.IsAbosutePath(pathConfigFile) {
pathConfigFile = vari.ExeDir + pathConfigFile
}
yamlContent, err := ioutil.ReadFile(pathConfigFile)
yamlContent = ReplaceSpecialChars(yamlContent) yamlContent = ReplaceSpecialChars(yamlContent)
if err != nil { if err != nil {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_read_file", path), color.FgCyan) logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_read_file", pathConfigFile), color.FgCyan)
return configDef return configDef
} }
err = yaml.Unmarshal(yamlContent, &configDef) err = yaml.Unmarshal(yamlContent, &configDef)
if err != nil { if err != nil {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_parse_file", path), color.FgCyan) logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("fail_to_parse_file", pathConfigFile), color.FgCyan)
return configDef return configDef
} }
......
...@@ -28,6 +28,7 @@ func ParseRequestParams(req *http.Request) (defaultFile, yamlFile, fields string ...@@ -28,6 +28,7 @@ func ParseRequestParams(req *http.Request) (defaultFile, yamlFile, fields string
human = GetRequestParams(query,"human", "H") human = GetRequestParams(query,"human", "H")
if req.Method == http.MethodPost { if req.Method == http.MethodPost {
// save to files
req.ParseForm() req.ParseForm()
defaultDefContent := req.FormValue("default") defaultDefContent := req.FormValue("default")
configDefContent := req.FormValue("config") configDefContent := req.FormValue("config")
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"strings"
) )
func PostForm(urlStr string, data url.Values) (interface{}, bool) { func PostForm(urlStr string, data url.Values) (interface{}, bool) {
...@@ -33,15 +32,7 @@ func PostForm(urlStr string, data url.Values) (interface{}, bool) { ...@@ -33,15 +32,7 @@ func PostForm(urlStr string, data url.Values) (interface{}, bool) {
return body, true return body, true
} }
func GenUrl(server string, path string) string { func GenUrl(server string, port int, path string) string {
server = UpdateUrl(server) url := fmt.Sprintf("http://%s:%d/%s", server, port, path)
url := fmt.Sprintf("%s%s", server, path)
return url
}
func UpdateUrl(url string) string {
if strings.LastIndex(url, "/") < len(url)-1 {
url += "/"
}
return url return url
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册