-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a method to making http (GET for now) requests
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package requests | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
func doRequest(method string, url string) (*http.Response, error) { | ||
|
||
req, err := http.NewRequest(method, url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
client := http.Client{} | ||
|
||
req.Header.Set("User-Agent", "go-tools by @skorp || github.com/skorp") | ||
resp, err := client.Do(req) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
return resp, err | ||
} | ||
|
||
// GET request. | ||
func GET(url string) (*http.Response, error) { | ||
|
||
return doRequest("GET", url) | ||
} |