提交 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
$>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.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 -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两个文件的
$>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.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 -c demo\default.yaml -i test.txt --decode 将-i指定的文件根据-d参数的配置进行解析。
......
......@@ -3,6 +3,7 @@ package gen
import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
......@@ -17,32 +18,40 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
configDef := model.DefData{}
// load defaultDef
path := vari.ExeDir + 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)
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
}
err = yaml.Unmarshal(defaultContent, &defaultDef)
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
}
}
// load configDef
path = vari.ExeDir + configFile
yamlContent, err := ioutil.ReadFile(path)
pathConfigFile := configFile
if !fileUtils.IsAbosutePath(pathConfigFile) {
pathConfigFile = vari.ExeDir + pathConfigFile
}
yamlContent, err := ioutil.ReadFile(pathConfigFile)
yamlContent = ReplaceSpecialChars(yamlContent)
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
}
err = yaml.Unmarshal(yamlContent, &configDef)
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
}
......
......@@ -28,6 +28,7 @@ func ParseRequestParams(req *http.Request) (defaultFile, yamlFile, fields string
human = GetRequestParams(query,"human", "H")
if req.Method == http.MethodPost {
// save to files
req.ParseForm()
defaultDefContent := req.FormValue("default")
configDefContent := req.FormValue("config")
......
......@@ -7,7 +7,6 @@ import (
"log"
"net/http"
"net/url"
"strings"
)
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
}
func GenUrl(server string, path string) string {
server = UpdateUrl(server)
url := fmt.Sprintf("%s%s", server, path)
return url
}
func UpdateUrl(url string) string {
if strings.LastIndex(url, "/") < len(url)-1 {
url += "/"
}
func GenUrl(server string, port int, path string) string {
url := fmt.Sprintf("http://%s:%d/%s", server, port, path)
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.
先完成此消息的编辑!
想要评论请 注册