fix merge log json bug
This commit is contained in:
parent
6b39392dfb
commit
17ad8486a6
3 changed files with 136 additions and 79 deletions
|
|
@ -176,10 +176,11 @@ func (s *Server) createHandler() {
|
|||
}
|
||||
defer merge_api.Close()
|
||||
log.Println("Locate python api", merge_api.Name())
|
||||
cmd := exec.Command(py_exec, merge_api.Name(), "merge", master_path, dev_path, output_path, changelog_path, "debug")
|
||||
cmd := exec.Command(py_exec, merge_api.Name(), "merge", master_path, dev_path, output_path, changelog_path)
|
||||
|
||||
log.Println("Run merge command", cmd)
|
||||
err = cmd.Run()
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Println(string(out))
|
||||
if err != nil {
|
||||
log.Fatalln("Merge request failed. Python merge failed: ", err)
|
||||
}
|
||||
|
|
@ -190,8 +191,28 @@ func (s *Server) createHandler() {
|
|||
|
||||
})
|
||||
|
||||
r.Get("/dllog", func(w http.ResponseWriter, r *http.Request) {
|
||||
changelog_path := "cofffeemachineConfig/changelog/testlog.html"
|
||||
r.Post("/dllog", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var postRequest map[string]interface{}
|
||||
err := json.NewDecoder(r.Body).Decode(&postRequest)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
log.Fatalln("Log request failed: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
file_ext := ".html"
|
||||
if rb, ok := postRequest["htmlfile"].(bool); ok {
|
||||
if rj, ok := postRequest["requestJson"].(bool); ok {
|
||||
if rj {
|
||||
file_ext = ".json"
|
||||
}
|
||||
} else if !rb {
|
||||
file_ext = ".log"
|
||||
}
|
||||
}
|
||||
|
||||
changelog_path := "cofffeemachineConfig/changelog/testlog" + file_ext
|
||||
logFile, err := os.Open(changelog_path)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
|
@ -199,14 +220,29 @@ func (s *Server) createHandler() {
|
|||
|
||||
defer logFile.Close()
|
||||
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=logfile.html")
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
if file_ext == ".json" {
|
||||
|
||||
_, err = io.Copy(w, logFile)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
var logFileJson map[string]interface{}
|
||||
err = json.NewDecoder(logFile).Decode(&logFileJson)
|
||||
if err != nil {
|
||||
log.Fatalf("Error when decode log file: %s", err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(logFileJson)
|
||||
log.Println("Log file: ", changelog_path)
|
||||
} else {
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=logfile"+file_ext)
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
|
||||
_, err = io.Copy(w, logFile)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
// Recipe Router
|
||||
rr := routers.NewRecipeRouter(database)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue