From ee709e790d5866b3f5d5ef70b015729c522e63a6 Mon Sep 17 00:00:00 2001 From: Emile Date: Tue, 12 Feb 2019 23:15:19 +0100 Subject: finally finished implementing the updateCenterOfMass handler and because that was so much fun, I also implemented the genForestTreeHandler ... --- main.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 37586a6..07fbc36 100644 --- a/main.go +++ b/main.go @@ -147,6 +147,34 @@ func updateTotalMassHandler(w http.ResponseWriter, r *http.Request) { updateTotalMassEndpoint(index) } +func updateCenterOfMassHandler(w http.ResponseWriter, r *http.Request) { + log.Println("[ ] The updateCenterOfMassHandler was accessed") + + // get the star by parsing http-post parameters + errParseForm := r.ParseForm() // parse the POST form + if errParseForm != nil { // handle errors + panic(errParseForm) + } + + // get the tree into which the star should be inserted into + index, _ := strconv.ParseInt(r.Form.Get("index"), 10, 64) + + updateCenterOfMassEndpoint(index) +} + +func genForestTreeHandler(w http.ResponseWriter, r *http.Request) { + log.Println("[ ] The genForestTreeHandler was accessed") + + vars := mux.Vars(r) + treeindex, parseIntErr := strconv.ParseInt(vars["treeindex"], 10, 64) + if parseIntErr != nil { + panic(parseIntErr) + } + + tree := genForestTreeEndpoint(treeindex) + _, _ = fmt.Fprintf(w, "%s", tree) +} + func main() { router := mux.NewRouter() @@ -161,8 +189,10 @@ func main() { router.HandleFunc("/insertList", insertListHandler).Methods("POST") router.HandleFunc("/updatetotalmass", updateTotalMassHandler).Methods("POST") + router.HandleFunc("/updatecenterofmass", updateCenterOfMassHandler).Methods("POST") + + router.HandleFunc("/genforesttree/{treeindex}", genForestTreeHandler).Methods("GET") - //router.HandleFunc("/updatecenterofmass/{treeindex}", updateCenterOfMassHandler).Methods("GET") //router.HandleFunc("/metrics", metricHandler).Methods("GET") //router.HandleFunc("/export/{treeindex}", exportHandler).Methods("POST") //router.HandleFunc("/nrofgalaxies", nrofgalaxiesHandler).Methods("GET") -- cgit 1.4.1