about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-12-24 22:53:42 +0100
committerhanemile <hanemile@protonmail.com>2018-12-24 22:53:42 +0100
commit306c2a9871a4f12519ef56f7ca9fa4a272381e32 (patch)
tree670deea0e0bf659e73dd396b36308cf4403f58f0
parent434bcfcd4b1a723106015edea66538bff84a6a3d (diff)
cron commit
-rw-r--r--Dockerfile14
-rw-r--r--README.md6
-rw-r--r--docker-compose.yml7
-rw-r--r--main.go53
4 files changed, 79 insertions, 1 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..9cfbfba
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,14 @@
+FROM golang:latest
+
+# Setup the work directory
+WORKDIR /home
+
+# Copy the files to WORKDIR
+COPY main.go /home/main.go
+
+# Install the used go packages
+RUN ["go", "get", "git.darknebu.la/GalaxySimulator/structs"]
+RUN ["go", "get", "github.com/gorilla/mux"]
+
+# Start the webserver
+ENTRYPOINT ["go", "run", "/home/main.go"]
diff --git a/README.md b/README.md
index bcdf634..1e84758 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
 # simulator-container
 
-Docker-container simulating the new position of a given set of stars.
\ No newline at end of file
+Docker-container simulating the new position of a given set of stars.
+
+## Purpose
+
+This containers purpose is to get a star and return the position of the star after a given time delta.
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..f0c08d8
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,7 @@
+version: '3'
+
+services:
+  simulate:
+    build: .
+    ports:
+      - "8345:8345"
\ No newline at end of file
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..c33a669
--- /dev/null
+++ b/main.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"strconv"
+
+	"github.com/gorilla/mux"
+
+	"git.darknebu.la/GalaxySimulator/structs"
+)
+
+func nextpos(deltat float64, star structs.Star2D) {
+	// ...
+}
+
+func initMassCenter(w http.ResponseWriter, r *http.Request) {
+	log.Println("[   ] Initializing the Mass Center of all the nodes in the tree")
+
+	// getting the tree index
+	vars := mux.Vars(r)
+	treeindex, _ := strconv.ParseInt(vars["treeindex"], 10, 0)
+	_, _ = fmt.Fprintln(w, treeindex)
+
+	// Recursively calculate the center of mass of a node by calculating the center of mass of the four children of
+	// that node.
+	// The formula used is the following:
+	// ( (x_i * m_i)/(m_total) , (y_i * m_i)/(m_total) )
+
+	// starting at the root node of the tree
+
+}
+
+func calcNewPos(w http.ResponseWriter, r *http.Request) {
+	// get the post parameters
+	x, _ := strconv.ParseFloat(r.PostFormValue("x"), 64)
+	y, _ := strconv.ParseFloat(r.PostFormValue("y"), 64)
+	z, _ := strconv.ParseFloat(r.PostFormValue("z"), 64)
+
+	log.Printf("(%f, %f, %f)", x, y, z)
+}
+
+func main() {
+	router := mux.NewRouter()
+
+	router.HandleFunc("/initMassCenter", calcNewPos).Methods("POST")
+
+	// 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")
+	log.Fatal(http.ListenAndServe(":8345", router))
+}