From 64f62b4ebeb29b52ec8f32f7bf474243903395bf Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 23 Sep 2019 12:48:28 +0200 Subject: always return json the api simply always returns the result as json --- http.go | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/http.go b/http.go index 91c5c77..c1f1e6f 100644 --- a/http.go +++ b/http.go @@ -63,25 +63,18 @@ func getHandler(w http.ResponseWriter, r *http.Request) { RawTLE := strings.Join(lines[j:j+3], "\n") - // handle the response according to the query parameter "format" - // if ?format=json is given, return - if r.URL.Query().Get("format") == "json" { - w.Header().Set("Content-Type", "application/json") - - JSONTLE, err := tle.NewTLE(RawTLE) - if err != nil { - fmt.Println(err) - } + w.Header().Set("Content-Type", "application/json") - // convert the TLE to json - b, err := json.MarshalIndent(JSONTLE, "", " ") - if err != nil { - fmt.Println("error: ", err) - } - fmt.Fprintf(w, string(b)) - //fmt.Fprintf(w, "{\"response\": \"Getting the TLE for %s/%s as json\"}", vars["station"], vars["name"]) - } else { - fmt.Fprintf(w, "Getting the TLE for %s/%s raw", vars["station"], vars["name"]) + JSONTLE, err := tle.NewTLE(RawTLE) + if err != nil { + fmt.Println(err) + } + + // convert the TLE to json + b, err := json.MarshalIndent(JSONTLE, "", " ") + if err != nil { + fmt.Println("error: ", err) } + fmt.Fprintf(w, string(b)) } -- cgit 1.4.1