diff --git a/src/gen/decode.go b/src/gen/decode.go index 08bd9a6e781e37eb334451f6ea39915382fa9d97..34081eb84e68dcf409d6d15f726f994425dbdb1c 100644 --- a/src/gen/decode.go +++ b/src/gen/decode.go @@ -3,6 +3,7 @@ package gen import ( "encoding/json" "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" @@ -29,10 +30,12 @@ func Decode(defaultFile, configFile, fieldsToExportStr, input, output string) { ret := []map[string]interface{}{} LinesToMap(data, fieldsToExport, &ret) jsonObj, _ := json.Marshal(ret) - respJson := string(jsonObj) + vari.JsonResp = string(jsonObj) - fileUtils.WriteFile(output, respJson) logUtils.Screen(i118Utils.I118Prt.Sprintf("analyse_success", output )) + if vari.RunMode != constant.RunModeServerRequest { + fileUtils.WriteFile(output, vari.JsonResp) + } } func LinesToMap(str string, fieldsToExport []string, ret *[]map[string]interface{}) { diff --git a/src/service/request.go b/src/service/request.go index 09cd9898af083e80b3f807f558753f26c4ef1a3d..f23b9b8975c707099534b9a67a87737245616bd6 100644 --- a/src/service/request.go +++ b/src/service/request.go @@ -9,8 +9,8 @@ import ( "strconv" ) -func ParseRequestParams(req *http.Request) (root, defaultFile, yamlFile string, count int, - fields, human string, format, table string) { +func ParseRequestParams(req *http.Request) (root, defaultFile, yamlFile, fields string, count int, + human string, format, table string, decode bool, input, output string) { query := req.URL.Query() root = GetRequestParams(query,"root", "R") diff --git a/src/zd.go b/src/zd.go index 438eecd6765da753694c51d89a46827c87bb2018..edf8adf083355845130dcfc4584ee1a5ff85ced6 100644 --- a/src/zd.go +++ b/src/zd.go @@ -194,17 +194,17 @@ func StartServer() { } func DataHandler(w http.ResponseWriter, req *http.Request) { - root, defaultFile, configFile, count, fields, vari.HeadSep, - format, table = service.ParseRequestParams(req) - - if defaultFile == "" && configFile == "" { - return + root, defaultFile, configFile, fields, count, vari.HeadSep, + format, table, decode, input, output = service.ParseRequestParams(req) + + if decode { + gen.Decode(defaultFile, configFile, fields, input, output) + fmt.Fprintln(w, vari.JsonResp) + } else if defaultFile != "" || configFile != "" { + vari.RunMode = constant.RunModeServerRequest + toGen() + fmt.Fprintln(w, vari.JsonResp) } - - vari.RunMode = constant.RunModeServerRequest - output = "" - toGen() - fmt.Fprintln(w, vari.JsonResp) } func init() {