Skip to content

Commit

Permalink
adding a method to making http (GET for now) requests
Browse files Browse the repository at this point in the history
  • Loading branch information
skorp committed May 27, 2020
1 parent b28cc7e commit 4eb9561
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

main.go
30 changes: 30 additions & 0 deletions fetch/requests.go
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)
}

0 comments on commit 4eb9561

Please sign in to comment.