From 964794bd9876e0ef0cde7995e6c1c763aa20c2b9 Mon Sep 17 00:00:00 2001 From: Emile Date: Fri, 27 Sep 2019 20:23:04 +0200 Subject: updated the getTLE Endpoint the category and name get set using http parameters now --- http.go | 9 ++++----- server.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/http.go b/http.go index 9808f07..48c8dca 100644 --- a/http.go +++ b/http.go @@ -9,7 +9,6 @@ import ( "strings" tle "git.darknebu.la/Satellite/tle" - "github.com/gorilla/mux" ) // indexHandler displays an index page @@ -27,14 +26,14 @@ func dumpallHandler(w http.ResponseWriter, r *http.Request) { // get Handler returns the specified TLE func getHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) + r.ParseForm() // define where the file containing the spoecified categories lies - categoryPath := fmt.Sprintf("data/%s.txt", vars["station"]) + categoryPath := fmt.Sprintf("data/%s.txt", r.FormValue("category")) // this will only download the category if the file does not exist or if it // is to old - downloadCategory(vars["station"]) + downloadCategory(r.FormValue("category")) // open the file containing the data for the individual station content, err := ioutil.ReadFile(categoryPath) @@ -47,7 +46,7 @@ func getHandler(w http.ResponseWriter, r *http.Request) { // iterate over all lines searching for the satellite var j int for i, line := range lines { - if strings.Contains(line, vars["name"]) { + if strings.Contains(line, r.FormValue("name")) { j = i break } diff --git a/server.go b/server.go index 280d359..974724c 100644 --- a/server.go +++ b/server.go @@ -32,7 +32,7 @@ func main() { r.HandleFunc("/", indexHandler) r.HandleFunc("/v1/dumpall", dumpallHandler) r.HandleFunc("/v1/all", printAllHandler) - r.HandleFunc("/v1/{station}/{name}", getHandler) + r.HandleFunc("/v1/getTLE", getHandler) // Start the http server using the port provided using command line arguments // The Default port is 8080 -- cgit 1.4.1