From 48451fa85af62d28bfb9257ae8c2b05cecea80fe Mon Sep 17 00:00:00 2001 From: hanemile Date: Wed, 23 Jan 2019 20:25:44 +0100 Subject: push before using everything in docker swarm --- main.go | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 680b8ed..572bcfd 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io/ioutil" "log" "net/http" @@ -11,8 +12,9 @@ import ( ) var ( - treeArray []*structs.Node - starCount []int + treeArray []*structs.Node + starCount []int + errorCount []int ) // indexHandler @@ -26,15 +28,39 @@ API: - /insert/{treeindex} ("POST") - /starlist/{treeindex} ("GET") - /dumptree/{treeindex} ("GET") + - /updatetotalmass/{treeindex} ("GET") - /updatecenterofmass/{treeindex} ("GET") + - /metrics ("GET") - /export/{treeindex} ("POST") - - /fastinsert/{filename} ("POST") + + - /fastinsertjson/{filename} ("GET") + - /fastinsertlist/{filename} ("GET") + + - /readdir ("GET") ` _, _ = fmt.Fprintf(w, infostring) } +func readdirHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + dirname := vars["dirname"] + log.Printf("Reading from %s", dirname) + + files, err := ioutil.ReadDir(fmt.Sprintf("./%s", dirname)) + log.Println(files) + log.Println(err) + if err != nil { + fmt.Println(err) + } + + for _, f := range files { + fmt.Println(f.Name()) + _, _ = fmt.Fprintf(w, "%v", f.Name()) + } +} + func main() { router := mux.NewRouter() @@ -48,7 +74,11 @@ func main() { 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") + + router.HandleFunc("/fastinsertjson/{filename}", fastInsertJSONHandler).Methods("GET") + router.HandleFunc("/fastinsertlist/{filename}/{treeindex}", fastInsertListHandler).Methods("GET") + + router.HandleFunc("/readdir/{dirname}", readdirHandler).Methods("GET") fmt.Println("Database Container up") log.Fatal(http.ListenAndServe(":80", router)) -- cgit 1.4.1