about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-09-23 12:47:51 +0200
committerEmile <hanemile@protonmail.com>2019-09-23 12:47:51 +0200
commiteb2e3dc097927399c0c8d1de790702bd8ef9e9fe (patch)
treeada7b5f6a9d4252c3c2b4301c2c766bff140ba45
parent52754aaaaa4b133834eab940e234df4a83837202 (diff)
caching
find out if the categories file exists, if not, download it
-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)