diff options
author | Andinus <andinus@inventati.org> | 2020-03-16 17:29:15 +0530 |
---|---|---|
committer | Andinus <andinus@inventati.org> | 2020-03-16 17:29:15 +0530 |
commit | b75359931e3c5baaded6d0addb6d28f750dcd518 (patch) | |
tree | d21197d18dad2bc58d081263c0192abc7110edaa /hibp/req.go | |
parent | 553079dc017a44164cd04d4c067c061003e1684f (diff) | |
download | orion-b75359931e3c5baaded6d0addb6d28f750dcd518.tar.gz |
Add initial version of orion v0.1.0
Diffstat (limited to 'hibp/req.go')
-rw-r--r-- | hibp/req.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/hibp/req.go b/hibp/req.go new file mode 100644 index 0000000..a3085da --- /dev/null +++ b/hibp/req.go @@ -0,0 +1,35 @@ +package hibp + +import ( + "fmt" + "io/ioutil" + "net/http" +) + +func reqHIBP(reqApi string) (string, error) { + req, err := http.NewRequest(http.MethodGet, reqApi, nil) + if err != nil { + return "", fmt.Errorf("request init failed\n%s", + err.Error()) + } + + c := http.Client{} + res, err := c.Do(req) + if err != nil { + return "", fmt.Errorf("request failed\n%s", + err.Error()) + } + defer res.Body.Close() + + if res.StatusCode != 200 { + return "", fmt.Errorf("Unexpected response status code received: %d %s", + res.StatusCode, http.StatusText(res.StatusCode)) + } + + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return "", fmt.Errorf("reading res.Body failed\n%s", + err.Error()) + } + return string(body), err +} |