about summary refs log tree commit diff
path: root/main.go
blob: cdb21c8fb6963a076dc26007633a517edbd5e4cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gorilla/mux"

	"git.darknebu.la/GalaxySimulator/structs"
)

var (
	treeArray []*structs.Node
	starCount []int
)

// indexHandler
func indexHandler(w http.ResponseWriter, r *http.Request) {
	infostring := `Galaxy Simulator Database

API:
	/ GET
	/new POST w float64
	/insert/{treeindex} POST x float64, y float64, vx float64, vy float64, m float64
	/starlist/{treeindex}
	/printall GET
	/metrics GET
`
	_, _ = fmt.Fprintf(w, infostring)
}

func main() {
	router := mux.NewRouter()

	router.HandleFunc("/", indexHandler).Methods("GET")
	router.HandleFunc("/new", newTreeHandler).Methods("POST")
	router.HandleFunc("/printall", printAllHandler).Methods("GET")
	router.HandleFunc("/insert/{treeindex}", insertStarHandler).Methods("POST")
	router.HandleFunc("/starlist/{treeindex}", starlistHandler).Methods("GET")
	router.HandleFunc("/dumptree/{treeindex}", dumptreeHandler).Methods("GET")
	router.HandleFunc("/updatetotalmass/{treeindex}", updateTotalMassHandler).Methods("GET")
	router.HandleFunc("/updatecenterofmass/{treeindex}", updateCenterOfMassHandler).Methods("GET")
	router.HandleFunc("/metrics", metricHandler).Methods("GET")
	router.HandleFunc("/export/{treeindex}", exportHandler).Methods("POST")
	router.HandleFunc("/fastinsert/{filename}", fastInsertHandler).Methods("POST")

	fmt.Println("Database Container up")
	log.Fatal(http.ListenAndServe(":80", router))
}