about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-09-27 20:23:04 +0200
committerEmile <hanemile@protonmail.com>2019-09-27 20:23:04 +0200
commit964794bd9876e0ef0cde7995e6c1c763aa20c2b9 (patch)
tree57f2e28f6a6bce304a78c11b54e73ee0bd5b346f
parent34325da4b44987eafce6144cf9e360615b54ea8f (diff)
updated the getTLE Endpoint
the category and name get set using http parameters now
-rw-r--r--http.go9
-rw-r--r--server.go2
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