-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstracted JSON request as interface
- Loading branch information
1 parent
91796b6
commit 4eb94b1
Showing
1 changed file
with
35 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
type Requester interface { | ||
BuildPath() string | ||
} | ||
|
||
//requests the JSON data for all fields in a Clickup task or subtask | ||
func GetJSON(r Requester) []byte { | ||
apiPath := r.BuildPath() | ||
token := viper.GetString("ctoken") | ||
client := &http.Client{} | ||
|
||
req, _ := http.NewRequest(http.MethodGet, apiPath, nil) | ||
|
||
req.Header.Add("Authorization", token) | ||
req.Header.Add("Content-Type", "application/json") | ||
resp, err := client.Do(req) | ||
|
||
if err != nil { | ||
fmt.Println("Errored when sending request to the server") | ||
} | ||
|
||
defer resp.Body.Close() | ||
resp_body, _ := ioutil.ReadAll(resp.Body) | ||
|
||
return resp_body | ||
} |