about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--http.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/http.go b/http.go
index d1cfb48..91c5c77 100644
--- a/http.go
+++ b/http.go
@@ -6,6 +6,7 @@ import (
 	"io/ioutil"
 	"log"
 	"net/http"
+	"os"
 	"strings"
 
 	tle "git.darknebu.la/Satellite/tle"
@@ -34,8 +35,16 @@ func getHandler(w http.ResponseWriter, r *http.Request) {
 	//			- dump all if not present
 	//			- if old, fetch from celestrack
 
-	// open the file containing the data for the individual station
+	// define where the file containing the spoecified categories lies
 	categoryPath := fmt.Sprintf("data/%s.txt", vars["station"])
+
+	// find out if the file exists or not
+	if _, err := os.Stat(categoryPath); os.IsNotExist(err) {
+		// if it does not exist, download the category
+		downloadCategory(vars["station"])
+	}
+
+	// open the file containing the data for the individual station
 	content, err := ioutil.ReadFile(categoryPath)
 	if err != nil {
 		log.Printf("Could not open %s", categoryPath)