about summary refs log tree commit diff
diff options
context:
space:
mode:
-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")
 }