diff options
author | Emile <hanemile@protonmail.com> | 2019-02-28 18:39:47 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-02-28 18:39:47 +0100 |
commit | c66eff670c050730a133062144679bce56d58b3b (patch) | |
tree | 4a910dc3afb9063e6cc637cd9a74b8dcc1e18d2a | |
parent | 932f7e8b1451814606d3bb41e2b6272a937e3e82 (diff) |
commented stuff and adjusted error values
-rw-r--r-- | main.go | 12 |
1 files 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) |