summaryrefslogtreecommitdiff
path: root/src/server.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-18 10:45:10 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:15 +0200
commit343836597df3efd6f31a68e29ff82b6ec4979f69 (patch)
treefa00080e0379859a9b4b770bbd36743f56731d61 /src/server.go
parent42488834f8f60627830732428017cdf26733f12c (diff)
Move HTTP GET/POST methods to its own file
Diffstat (limited to 'src/server.go')
-rw-r--r--src/server.go27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/server.go b/src/server.go
index ca130d0..ced7716 100644
--- a/src/server.go
+++ b/src/server.go
@@ -2,31 +2,8 @@ package eduvpn
import (
"fmt"
- "io/ioutil"
- "net/http"
)
-func getFileUrl(url string) ([]byte, error) {
- // Do a Get request to the specified url
- resp, reqErr := http.Get(url)
- if reqErr != nil {
- return nil, &HTTPResourceError{URL: url, Err: reqErr}
- }
- // Close the response body at the end
- defer resp.Body.Close()
-
- // Check if http response code is ok
- if resp.StatusCode != http.StatusOK {
- return nil, &HTTPStatusError{URL: url, Status: resp.StatusCode}
- }
- // Read the body
- body, readErr := ioutil.ReadAll(resp.Body)
- if readErr != nil {
- return nil, &HTTPReadError{URL: url, Err: readErr}
- }
- return body, nil
-}
-
type DiscoFileError struct {
URL string
Err error
@@ -60,7 +37,7 @@ func getDiscoFile(jsonFile string) (string, error) {
// Get json data
discoURL := "https://disco.eduvpn.org/v2/"
fileURL := discoURL + jsonFile
- fileBody, fileErr := getFileUrl(fileURL)
+ fileBody, fileErr := HTTPGet(fileURL)
if fileErr != nil {
return "", &DiscoFileError{fileURL, fileErr}
@@ -69,7 +46,7 @@ func getDiscoFile(jsonFile string) (string, error) {
// Get signature
sigFile := jsonFile + ".minisig"
sigURL := discoURL + sigFile
- sigBody, sigFileErr := getFileUrl(sigURL)
+ sigBody, sigFileErr := HTTPGet(sigURL)
if sigFileErr != nil {
return "", &DiscoSigFileError{URL: sigURL, Err: sigFileErr}