about summary refs log tree commit diff
path: root/main.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-02-12 23:15:19 +0100
committerEmile <hanemile@protonmail.com>2019-02-12 23:15:19 +0100
commitee709e790d5866b3f5d5ef70b015729c522e63a6 (patch)
treeedaa50050aad9fe193dfb521029a0682d4986674 /main.go
parent10366e331346dbcce6c9e0fe8651f0dfe9743a8f (diff)
finally finished implementing the updateCenterOfMass handler and because that was so much fun, I also implemented the genForestTreeHandler ...
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 31 insertions, 1 deletions
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")