From 92ef35defb898ef0183c2d4ee0835fe7dd1ba9bd Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 12 Jan 2019 23:26:41 +0100 Subject: something seems broken... --- main.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index c17902e..963b1c6 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,7 @@ func calcNewPos(w http.ResponseWriter, r *http.Request) { vy, _ := strconv.ParseFloat(r.PostFormValue("vy"), 64) m, _ := strconv.ParseFloat(r.PostFormValue("m"), 64) - log.Println("Simulator container calcNewPos git these values: ") + log.Println("Simulator container calcNewPos got these values: ") log.Printf("(x: %f, y: %f, vx: %f, vy: %f, m: %f)\n", x, y, vx, vy, m) } @@ -48,16 +48,37 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { _, _ = fmt.Fprintf(w, "Hello, this is the simu container!") } -func main() { - router := mux.NewRouter() +func calcallforcesHandler(w http.ResponseWriter, r *http.Request) { + fmt.Println("The calcallforcesHandler was accessed!") - router.HandleFunc("/initMassCenter", calcNewPos).Methods("POST") + vars := mux.Vars(r) + treeindex, _ := strconv.ParseInt(vars["treeindex"], 10, 0) - // this is an endpoint searching for a star and calculating the forces acting inbetween it and all the other star - // in it's direct range - router.HandleFunc("/newpos", calcNewPos).Methods("POST") + if r.Method == "GET" { + _, _ = fmt.Fprintf(w, "Make a post request to this endpoint to calc some forces!") + fmt.Println(treeindex) + } else { + // get the post parameters + x, _ := strconv.ParseFloat(r.PostFormValue("x"), 64) + y, _ := strconv.ParseFloat(r.PostFormValue("y"), 64) + vx, _ := strconv.ParseFloat(r.PostFormValue("vx"), 64) + vy, _ := strconv.ParseFloat(r.PostFormValue("vy"), 64) + m, _ := strconv.ParseFloat(r.PostFormValue("m"), 64) + + log.Println("Simulator container calcallforces got these values: ") + log.Printf("(x: %f, y: %f, vx: %f, vy: %f, m: %f)\n", x, y, vx, vy, m) + _, _ = fmt.Fprintf(w, "calculating forces...") + _, _ = fmt.Fprintf(w, "Simu here, calculating the forces acting on the star (%f, %f)", x, y) + } +} + +func main() { + router := mux.NewRouter() router.HandleFunc("/", indexHandler).Methods("GET") + router.HandleFunc("/newpos", calcNewPos).Methods("POST") + router.HandleFunc("/initMassCenter", calcNewPos).Methods("POST") + router.HandleFunc("/calcallforces/{treeindex}", calcallforcesHandler).Methods("GET", "POST") - log.Fatal(http.ListenAndServe(":8002", router)) + log.Fatal(http.ListenAndServe(":80", router)) } -- cgit 1.4.1