From c66eff670c050730a133062144679bce56d58b3b Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 28 Feb 2019 18:39:47 +0100 Subject: commented stuff and adjusted error values --- main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 6d9ac30..16090d7 100644 --- a/main.go +++ b/main.go @@ -20,10 +20,12 @@ type point struct { // make a request to the nfw api and return the result func netNFW(x float64, y float64, z float64) (float64, error) { + // get the url of the nfw container or a reverse proxy handling the request to the containers var nfwurl = os.Getenv("nfwurl") + + // if no url is given, ask if nfwurl == "" { - log.Println("no nfwurl given! set one using the nfwurl environment variable!") - return -1, nil + return 0, fmt.Errorf("No nfwurl given!") } // build the request string @@ -31,21 +33,19 @@ func netNFW(x float64, y float64, z float64) (float64, error) { // make the request resp, err := http.Get(randMinRequestURL) + defer resp.Body.Close() if err != nil { panic(err) } - // close the request body when finished - defer resp.Body.Close() - // read the body body, bodyerr := ioutil.ReadAll(resp.Body) if bodyerr != nil { panic(bodyerr) } + // define an interface into which the nfw gets unpacked var dat map[string]interface{} - jsonerr := json.Unmarshal(body, &dat) if jsonerr != nil { panic(jsonerr) -- cgit 1.4.1