From eb2e3dc097927399c0c8d1de790702bd8ef9e9fe Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 23 Sep 2019 12:47:51 +0200 Subject: caching find out if the categories file exists, if not, download it --- http.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) -- cgit 1.4.1