about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-09-23 12:39:30 +0200
committerEmile <hanemile@protonmail.com>2019-09-23 12:39:30 +0200
commit205c92b576475a3224d88bfef7aa927ca29e08c1 (patch)
tree4b19b8c24b1a2a302dc37d9784dc75bfe786d8ba
parent1b3545a9f69f61a503f1c996c199c38b11a78e7e (diff)
moved code
moved the code from the dumpallHandler into the dumpall function located in the funcs.go file
-rw-r--r--funcs.go26
-rw-r--r--http.go27
2 files changed, 29 insertions, 24 deletions
diff --git a/funcs.go b/funcs.go
index 5ab913c..fbcd62d 100644
--- a/funcs.go
+++ b/funcs.go
@@ -6,6 +6,7 @@ import (
 	"log"
 	"net/http"
 	"os"
+	"strings"
 )
 
 // downloadCategory downloads the given category from celestrack
@@ -39,3 +40,28 @@ func downloadCategory(categoryName string) {
 		fmt.Printf("Could not write to file data/%s.txt", categoryName)
 	}
 }
+
+// dumpall dumps all the categories into the data folder
+func dumpall() {
+	// read the name of the categories from the categories.txt file and write
+	// the result to the categories slice
+	content, err := ioutil.ReadFile("categories.txt")
+	if err != nil {
+		log.Printf("%s\n", "could not read categories.txt file!")
+	}
+	lines := strings.Split(string(content), "\n")
+
+	for _, line := range lines {
+		if line != "" {
+			categories = append(categories, line)
+		}
+	}
+
+	// download all the categories to the data/<category name> directory
+	for _, category := range categories {
+		fmt.Fprintf(w, "downloading %s... ", category)
+		log.Printf("downloading %s... ", category)
+		downloadCategory(category)
+		fmt.Fprintf(w, "done.\n")
+	}
+}
diff --git a/http.go b/http.go
index ece4fde..d1cfb48 100644
--- a/http.go
+++ b/http.go
@@ -14,35 +14,14 @@ import (
 
 // indexHandler displays an index page
 func indexHandler(w http.ResponseWriter, r *http.Request) {
-	fmt.Fprintf(w, "%s", "<h1>Hello World</h1>")
+	fmt.Fprintf(w, "%s", "<h1>TLE2JSON api</h1>")
+	fmt.Fprintf(w, "%s", "Usage: Make a get request to /{station}/{name}")
 }
 
 // dumpallHandler dumps all categories
 func dumpallHandler(w http.ResponseWriter, r *http.Request) {
 	log.Println("[ ] Dumping all TLEs")
-
-	// read the name of the categories from the categories.txt file and write
-	// the result to the categories slice
-	content, err := ioutil.ReadFile("categories.txt")
-	if err != nil {
-		log.Printf("%s\n", "could not read categories.txt file!")
-	}
-	lines := strings.Split(string(content), "\n")
-
-	for _, line := range lines {
-		if line != "" {
-			categories = append(categories, line)
-		}
-	}
-
-	// download all the categories to the data/<category name> directory
-	for _, category := range categories {
-		fmt.Fprintf(w, "downloading %s... ", category)
-		log.Printf("downloading %s... ", category)
-		downloadCategory(category)
-		fmt.Fprintf(w, "done.\n")
-	}
-
+	dumpall()
 	log.Println("[+] Done dumping all TLEs")
 }